Keyboard key state detection method, computer equipment and readable storage medium

By performing bit operations on the keyboard key status value to determine the trigger operation, the key status detection process is simplified, the problem of low efficiency in the existing technology is solved, and the efficiency of key status detection is improved.

CN118731664APending Publication Date: 2024-10-01SHENZHEN CITY SASWELL TECH DEV
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410674518.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-27
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The existing key algorithm uses a state machine to determine the keyboard key status, which results in a large number of codes, low conciseness, and low efficiency, which reduces the efficiency of detecting the keyboard key status.

Method used

By performing bit operations on the first button status value of each button at the current sampling time point and the second button status value at the previous sampling time point, the trigger operation of each button is determined, simplifying the code and improving detection efficiency.

Benefits of technology

The code is concise, the execution time is shortened, the efficiency of detecting keyboard key status is improved, and the problem of low efficiency of state machine judgment is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118731664A_ABST
    Figure CN118731664A_ABST
Patent Text Reader

Abstract

The invention discloses a key state detection method of a keyboard, computer equipment and a readable storage medium. The method comprises the following steps: acquiring a first key state value of each key in the keyboard at a current sampling time point and a second key state value of each key at a previous sampling time point; performing bit operation on the first key state value and the second key state value, and determining a trigger operation corresponding to each key; according to the triggering operation corresponding to each key, a key state detection result of the keyboard is determined, and the key state detection result comprises at least one of the following items: a key which is triggered to be loosened, a key which is triggered to be pressed, a key which is in a continuous pressing state and a key which is not triggered to be operated. According to the method, bit operation can be carried out on the key state values of each key at the two adjacent sampling time points, the calculation process is simple, codes are concise, the execution time of the codes is effectively shortened, and the efficiency of detecting the key state of the keyboard can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of key detection, and in particular to a keyboard key status detection method, a computer device and a readable storage medium. Background Art

[0002] At present, most of the existing key algorithms use a state machine to determine the key status of the keyboard. The code is large in number and not very concise, which results in a long time to execute the code, thereby reducing the efficiency of detecting the key status of the keyboard. Summary of the invention

[0003] The present application provides a keyboard key state detection method, a computer device and a computer-readable storage medium, which solves the problem of low efficiency in the related art of using a state machine to determine the key state of a keyboard.

[0004] In a first aspect, the present application provides a method for detecting a key state of a keyboard, the method comprising: obtaining a first key state value of each key in the keyboard at a current sampling time point and a second key state value at a previous sampling time point; performing a bit operation on the first key state value and the second key state value to determine a trigger operation corresponding to each of the keys; determining a key state detection result of the keyboard according to the trigger operation corresponding to each of the keys, the key state detection result comprising at least one of the following: a key that is triggered and released, a key that is triggered and pressed, a key that is in a continuously pressed state, and a key that has not triggered an operation.

[0005] In a second aspect, the present application further provides a computer device, the computer device comprising a memory and a processor;

[0006] The memory is used to store computer programs;

[0007] The processor is used to execute the computer program and implement the above-mentioned keyboard key state detection method when executing the computer program.

[0008] In a third aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor enables the processor to implement the keyboard key status detection method as described above.

[0009] The present application discloses a keyboard key state detection method, a computer device and a computer-readable storage medium. The key state detection method determines the trigger operation corresponding to each key by performing a bit operation on the first key state value of each key at the current sampling time point and the second key state value at the previous sampling time point. The method can perform a bit operation on the key state value of each key at two adjacent sampling time points. The calculation process is simple and the code is concise, which effectively shortens the execution time of the code, solves the problem of low efficiency in using a state machine to judge the key state of the keyboard in the related art, and can effectively improve the efficiency of detecting the key state of the keyboard. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0011] Figure 1 is a structural schematic diagram of a computer device provided in an embodiment of the present application;

[0012] Figure 2 is a schematic flow chart of a keyboard key state detection method provided in an embodiment of the present application;

[0013] Figure 3 is a schematic flowchart of the sub-steps of determining the trigger operation corresponding to each key provided in an embodiment of the present application;

[0014] Figure 4 is a schematic flow chart of another keyboard key state detection method provided in an embodiment of the present application;

[0015] Figure 5 It is a flow chart of a keyboard key state detection method provided in an embodiment of the present application;

[0016] Figure 6 This is a flow chart of another keyboard key status detection method provided in an embodiment of the present application. DETAILED DESCRIPTION

[0017] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0018] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0019] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0020] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0021] At present, most of the existing key algorithms use a state machine to determine the key status of the keyboard. They need to use elements such as state, transition, event, action and activity to detect the key status of the keyboard. The amount of code is large and the code is not concise, which results in a long time to execute the code, thereby reducing the efficiency of detecting the key status of the keyboard.

[0022] To this end, the embodiments of the present application provide a keyboard key state detection method, a computer device, and a computer-readable storage medium. The keyboard key state detection method can be applied to a computer device, and the trigger operation corresponding to each key is determined by performing a bit operation on the first key state value of each key at the current sampling time point and the second key state value at the previous sampling time point, so that the key state value of each key at two adjacent sampling time points can be bit-operated. The calculation process is simple and the code is concise, which effectively shortens the execution time of the code, solves the problem of low efficiency in using a state machine to judge the key state of the keyboard in the related art, and can effectively improve the efficiency of detecting the key state of the keyboard.

[0023] See also Figure 1 , Figure 1 1 is a schematic diagram of the structure of a computer device 100 provided in an embodiment of the present application. The computer device 100 may include a processor 1001, a memory 1002, and a keyboard 1003, wherein the processor 1001, the memory 1002, and the keyboard 1003 may be connected via a bus, and the bus may be any applicable bus such as an Inter-integrated Circuit (I2C) bus.

[0024] Exemplarily, the computer device 100 may be a device with key operations, such as a smart phone, a tablet computer, a laptop computer, a desktop computer, or other electronic devices.

[0025] The memory 1002 may include a storage medium and an internal memory. The storage medium may store an operating system and a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor 1001 may execute the keyboard key state detection method described in any embodiment.

[0026] The keyboard 1003 includes a plurality of keys.

[0027] The processor 1001 is used to provide computing and control capabilities and support the operation of the entire computer device 100 .

[0028] The processor 1001 may be a central processing unit (CPU), a general-purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other types of processors such as programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components. A general-purpose processor may be a microprocessor, or a general-purpose processor may be any conventional processor.

[0029] In one embodiment, the processor 1001 is used to run a computer program stored in the memory 1002 to implement the following steps:

[0030] Obtain a first key state value of each key in the keyboard at a current sampling time point and a second key state value at a previous sampling time point; perform bitwise operation on the first key state value and the second key state value to determine a trigger operation corresponding to each key; determine a key state detection result of the keyboard according to the trigger operation corresponding to each key, the key state detection result including at least one of the following: a key that is triggered and released, a key that is triggered and pressed, a key that is in a continuously pressed state, and a key that has not triggered an operation.

[0031] In one embodiment, when the processor 1001 performs a bitwise operation on the first button state value and the second button state value to determine the trigger operation corresponding to each button, it is configured to implement:

[0032] Determine each key as a target key in turn; perform XOR calculation on the first key state value and the second key state value of the target key to obtain an XOR calculation value corresponding to the target key, the XOR calculation value being used to indicate whether the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point; if it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point, determine the trigger operation of the target key according to the first key state and the second key state; if it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has not changed relative to the first key state at the previous sampling time point, determine the trigger operation of the target key according to the second key state value.

[0033] In one embodiment, when implementing the triggering operation of determining the target key according to the first key state and the second key state, the processor 1001 is used to implement:

[0034] If the first button state is a pressed state and the second button state is a released state, the trigger operation of the target button is determined to be a trigger release operation; if the first button state is a released state and the second button state is a pressed state, the trigger operation of the target button is determined to be a trigger press operation.

[0035] In one embodiment, when implementing the triggering operation of determining the target key according to the second key state value, the processor 1001 is used to implement:

[0036] The first button state value is updated according to the second button state value to obtain an updated first button state value; if the updated first button state value is a third preset value, it is determined that the triggering operation of the target button is a continuous pressing operation.

[0037] In one embodiment, after determining the key state detection result of the keyboard according to the trigger operation corresponding to each key, the processor 1001 is further configured to implement:

[0038] If there is at least one key in a continuously pressed state on the keyboard, the total continuously pressed duration corresponding to the keyboard is determined and / or the sub-continuous pressed duration corresponding to each key in a continuously pressed state is determined.

[0039] In one embodiment, the processor 1001, when determining the total continuous pressing time corresponding to the keyboard, is used to implement:

[0040] Determine the first number of times that keys on the keyboard are in a continuously pressed state at consecutive sampling time points; and determine the total continuous pressing time according to the interval between the first number and the sampling time point.

[0041] In one embodiment, when determining the sub-continuous pressing duration corresponding to each key in the continuous pressing state, the processor 1001 is used to implement:

[0042] Determine each key in a continuously pressed state as a key to be detected in turn; determine the second number of times that the key to be detected is in a pressed state at consecutive sampling time points; and determine the sub-continuous pressing time corresponding to the key to be detected based on the interval between the second number and the sampling time point.

[0043] Some embodiments of the present application are described in detail below in conjunction with the accompanying drawings. In the absence of conflict, the following embodiments and features of the embodiments can be combined with each other. Figure 2 , Figure 2 is a schematic flow chart of a keyboard key state detection method provided in an embodiment of the present application. Figure 2 As shown, the keyboard key state detection method includes steps S101 to S103.

[0044] Step S101: Obtain a first key state value of each key in the keyboard at a current sampling time point and a second key state value at a previous sampling time point.

[0045] In some embodiments, the key state value of each key in the keyboard can be sampled based on a preset sampling period to obtain the key state value of each key in the keyboard at each sampling time point, and save the key state value of each key at each sampling time point. A storage variable for storing key state values, such as keyTemp, can be defined, and the key state value of each key at each sampling time point is stored in the storage variable keyTemp. The key state values ​​of different keys at each sampling time point can be stored in different storage variables keyTemp, respectively, or the key state values ​​of all keys at each sampling time point can be stored in one storage variable keyTemp.

[0046] Exemplarily, the button state value can be obtained by detecting the level signal. For example, when a high level is detected, the button state value is 1, indicating that the button is in a pressed state; when a low level is detected, the button state value is 0, indicating that the button is in a released state. For another example, when a high level is detected, the button state value is 1, indicating that the button is in a released state; when a low level is detected, the button state value is 0, indicating that the button is in a pressed state. For ease of explanation, this article takes the example that the button state value is 1 to indicate a pressed state and the button state value is 0 to indicate a released state.

[0047] Exemplarily, the preset sampling period can be set according to actual conditions, and the specific value is not limited here. For example, the sampling period can be 10 milliseconds, that is, the key state value of each key in the keyboard is sampled every 10 milliseconds. The sampling time point can be expressed as t0, t1, t2, t3, etc. For example, the sampling time point t0 is 0 ms, the sampling time point t1 is 10 ms, the sampling time point t2 is 20 ms, and so on.

[0048] For example, when performing key state detection, the key state value of each key at two adjacent sampling time points can be obtained for bitwise operation. For example, for key A, the first key state value of key A at the current sampling time point t1 and the second key state value at the previous sampling time point t0 can be obtained.

[0049] Step S102: performing a bitwise operation on the first button state value and the second button state value to determine a trigger operation corresponding to each button.

[0050] Exemplarily, after obtaining the first key state value of each key in the keyboard at the current sampling time point and the second key state value at the previous sampling time point, a bit operation can be performed on the first key state value and the second key state value to determine the trigger operation corresponding to each key.

[0051] See also Figure 3 , Figure 3 is a schematic flow chart of the sub-steps of determining the trigger operation corresponding to each key provided by an embodiment of the present application. Figure 3 As shown, step S102 may include the following steps S1021 to S1024.

[0052] Step S1021, determine each key as a target key in turn.

[0053] Exemplarily, the status of each key in the keyboard may be detected, and for ease of explanation, each key may be determined as a target key in turn.

[0054] Step S1022: perform an XOR calculation on the first key state value and the second key state value of the target key to obtain an XOR calculation value corresponding to the target key, where the XOR calculation value is used to indicate whether the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point.

[0055] Exemplarily, for the target key A, the first key state value and the second key state value of the target key A may be XORed to obtain the XORed value corresponding to the target key A. For example, if the first key state value of the target key A is 0 and the second key state value is 1, the XORed value is 1; if the first key state value of the target key A is 0 and the second key state value is 0, the XORed value is 0.

[0056] Exemplarily, for the target key B, the first key state value and the second key state value of the target key B may be XORed to obtain the XORed value corresponding to the target key B. For example, if the first key state value of the target key B is 1 and the second key state value is 1, the XORed value is 0; if the first key state value of the target key B is 1 and the second key state value is 0, the XORed value is 1.

[0057] The XOR calculation value is used to indicate whether the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point.

[0058] In some embodiments, when the XOR calculation value is a first preset value, the second key state of the target key at the current sampling time point changes relative to the first key state at the previous sampling time point; when the XOR calculation value is a second preset value, the second key state of the target key at the current sampling time point does not change relative to the first key state at the previous sampling time point, wherein the first preset value is different from the second preset value.

[0059] Exemplarily, the first preset value may be 1 and the second preset value may be 0, that is, when the XOR calculation value is 1, the second key state of the target key at the current sampling time point changes relative to the first key state at the previous sampling time point; when the XOR calculation value is 0, the second key state of the target key at the current sampling time point does not change relative to the first key state at the previous sampling time point, wherein the first preset value is different from the second preset value.

[0060] In the above embodiment, by performing an XOR calculation on the first key state value and the second key state value of the target key, it can be determined based on the XOR calculation value whether the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point.

[0061] Step S1023: If it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point, determine the triggering operation of the target key according to the first key state and the second key state.

[0062] Exemplarily, after performing an XOR calculation on the first key state value and the second key state value of the target key to obtain the XOR calculation value corresponding to the target key, it can be determined based on the XOR calculation value whether the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point. If it is determined based on the XOR calculation value that the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point, then the trigger operation of the target key is determined based on the first key state and the second key state.

[0063] In some embodiments, determining the trigger operation of the target button according to the first button state and the second button state may include: if the first button state is a pressed state and the second button state is a released state, determining the trigger operation of the target button to be a trigger release operation; if the first button state is a released state and the second button state is a pressed state, determining the trigger operation of the target button to be a trigger press operation.

[0064] It should be noted that when it is determined that the key state of the target key has changed, the trigger operation of the target key can be judged according to the second key state at the current sampling time point and the first key state at the previous sampling time point. For example, if the first key state is a pressed state (i.e., the first key state value is 1) and the second key state is a released state (i.e., the second key state value is 0), then the trigger operation of the target key is determined to be a trigger release operation. For another example, if the first key state is a released state (i.e., the first key state value is 0) and the second key state is a pressed state (i.e., the second key state value is 1), then the trigger operation of the target key is determined to be a trigger press operation.

[0065] In the above embodiment, by comparing the first button state with the second button state, the triggering operation of the target button can be determined simply and conveniently.

[0066] Step S1024: If it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has not changed relative to the first key state at the previous sampling time point, determine the trigger operation of the target key according to the second key state value.

[0067] Exemplarily, when it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has not changed relative to the first key state at the previous sampling time point, the trigger operation of the target key can be determined according to the second key state value.

[0068] It should be noted that, in the embodiment of the present application, when it is determined that the key state of the target key has not changed, the triggering operation of the target key can be determined according to the second key state value or the first key state value.

[0069] Exemplarily, when the second button state is in a pressed state, it can be confirmed that the triggering operation of the target button is a continuous pressing operation. When the second button state is in a released state, it can be confirmed that the target button has not triggered an operation. It can be understood that since the second button state of the target button at the current sampling time point has not changed relative to the first button state at the previous sampling time point, that is, the second button state value of the target button at the current sampling time point has not changed relative to the first button state value at the previous sampling time point, if the second button state value is 1, the first button state value is also 1, so it can be determined that the triggering operation of the target button is a continuous pressing operation.

[0070] In some embodiments, determining the trigger operation of the target key according to the second key state value may include: updating the first key state value according to the second key state value to obtain an updated first key state value; if the updated first key state value is a third preset value, determining that the trigger operation of the target key is a continuous pressing operation.

[0071] For example, the third preset value may be 1, indicating a pressed state; if the second button state value is 1, the updated first button state is also 1, and it can be determined that the triggering operation of the target button is a continuous pressing operation. If the second button state value is 0, the updated first button state is also 0, and it can be determined that the target button has not triggered a pressing operation or a releasing operation.

[0072] In the above embodiment, by updating the first button state value according to the second button state value, it is convenient to subsequently determine the trigger operation corresponding to the button according to the button state value at the next sampling time point and the button state value at the current sampling time point.

[0073] Step S103, determine the key state detection result of the keyboard according to the trigger operation corresponding to each key, the key state detection result includes at least one of the following: a key that is triggered and released, a key that is triggered and pressed, a key that is in a continuously pressed state, and a key that has not triggered an operation.

[0074] It should be noted that a key that has not triggered an operation refers to a key that has not triggered release, pressing, or is in a continuously pressed state.

[0075] Exemplarily, after performing a bitwise operation on the first key state value and the second key state value to determine the trigger operation corresponding to each key, the key state detection result of the keyboard can be determined according to the trigger operation corresponding to each key. For example, for key A, if the trigger operation corresponding to key A is a trigger release operation, then key A can be determined to be a trigger release key. For another example, for key B, if the trigger operation corresponding to key B is a trigger press operation, then key B can be determined to be a trigger press key. For another example, for key C, if the trigger operation corresponding to key C is a continuous press operation, then key C can be determined to be a key in a pressed state.

[0076] In the embodiment of the present application, by determining the key state detection result of the keyboard according to the trigger operation corresponding to each key, the application layer can perform key logic operation according to the key that is triggered to be released, the key that is triggered to be pressed, the key that is in a continuously pressed state, and the corresponding continuously pressed time of the keyboard. The specific process of the key logic operation can be referred to the relevant technology and is not limited here.

[0077] In the above embodiment, the trigger operation corresponding to each key is determined by performing a bit operation on the first key state value of each key at the current sampling time point and the second key state value at the previous sampling time point. This can realize the bit operation on the key state value of each key at two adjacent sampling time points. The calculation process is simple and the code is concise, which effectively shortens the execution time of the code, solves the problem of low efficiency in using a state machine to judge the key state of the keyboard in the related technology, and can effectively improve the efficiency of detecting the key state of the keyboard.

[0078] See also Figure 4 , Figure 4 FIG. 1 is a schematic flow chart of another keyboard key state detection method provided in an embodiment of the present application. Figure 4 As shown, the following steps S201 to S204 may be included.

[0079] Step S201: Obtain a first key state value of each key in the keyboard at a current sampling time point and a second key state value at a previous sampling time point.

[0080] Step S202: performing a bitwise operation on the first button state value and the second button state value to determine a trigger operation corresponding to each button.

[0081] Step S203, determine the key state detection result of the keyboard according to the trigger operation corresponding to each key, the key state detection result includes at least one of the following: a key that is triggered and released, a key that is triggered and pressed, a key that is in a continuously pressed state, and a key that has not triggered an operation.

[0082] It can be understood that steps S201 to S203 are the same as the above-mentioned steps S101 to S103, and will not be repeated here.

[0083] Step S204: If there is at least one key in a continuously pressed state on the keyboard, determine the total continuously pressed time duration corresponding to the keyboard and / or determine the sub-continuous pressed time duration corresponding to each key in a continuously pressed state.

[0084] It should be noted that in an embodiment of the present application, when it is detected that there is a key on the keyboard in a continuously pressed state, the total continuous pressing time corresponding to the keyboard and / or the sub-continuous pressing time corresponding to each key in the continuously pressed state can also be detected, so as to accurately perform the corresponding key logic operation according to the total continuous pressing time or the sub-continuous pressing time.

[0085] For example, when the total continuous pressing time is greater than the first preset time threshold, the first key logic operation is executed; when the sub-continuous pressing time corresponding to the key is greater than the second preset time threshold, the second key logic operation corresponding to the key is executed. Among them, the first preset time threshold and the second preset time threshold can be set according to actual conditions, and the specific values ​​are not limited here. In the embodiment of the present application, the user can flexibly set the preset time threshold to achieve the processing of the long press action, which is highly applicable.

[0086] In some embodiments, determining the total continuous press duration corresponding to the keyboard may include: determining the first number of times that a key on the keyboard is in a continuous press state at consecutive sampling time points; and determining the total continuous press duration based on the interval between the first number and the sampling time point.

[0087] Exemplarily, the first number of times that a key on the keyboard is in a continuously pressed state at multiple consecutive sampling time points can be counted. For example, if a key on the keyboard is in a continuously pressed state at three consecutive sampling time points, the first number can be determined to be 3. Then, the total continuous pressing time is obtained based on the difference between the first number and the interval time of the sampling time point. The interval time of the sampling time points refers to the time between two adjacent sampling time points, which can be expressed as T.

[0088] The above embodiment determines the first number of times that keys on the keyboard are in a continuously pressed state at consecutive sampling time points, and determines the total continuous pressing time according to the interval between the first number and the sampling time point. This allows the long-pressed combination keys to be processed according to the total continuous pressing time when multiple keys are pressed.

[0089] It should be noted that in the embodiment of the present application, when multiple keys are pressed, in addition to being able to choose to process a combination of long-pressed keys, a single key can also be selected for processing. Moreover, when processing a single key, it is not affected by other keys, which can effectively improve the accuracy of the logical operation corresponding to the key processing.

[0090] In some embodiments, determining the sub-continuous pressing duration corresponding to each key in a continuously pressed state may include: determining each key in a continuously pressed state as a key to be detected in turn; determining the second number of times that the key to be detected is in a pressed state at consecutive sampling time points; and determining the sub-continuous pressing duration corresponding to the key to be detected based on the interval between the second number and the sampling time point.

[0091] It should be noted that in the embodiment of the present application, when multiple keys are pressed simultaneously, the continuous pressing duration of a key can be independently determined, and the logical operation of this key can be processed separately.

[0092] Exemplarily, for ease of explanation, each key in a continuously pressed state may be determined as a key to be detected in turn. The second number of times each key to be detected is in a pressed state at multiple consecutive sampling time points may be counted. For example, for key C to be detected, if key C to be detected is in a pressed state at four consecutive sampling time points, the second number may be determined to be 4. Then, based on the difference between the second number and the interval between the sampling time points, the sub-continuous pressing time corresponding to key C to be detected is obtained, and the sub-continuous pressing time is 4T.

[0093] See also Figure 5 , Figure 5 1 is a flowchart of a keyboard key state detection method provided by an embodiment of the present application. Figure 5 As shown, the following steps may be included:

[0094] Step 301: Input the key state value of each key in the sampling keyboard.

[0095] Step 302: XOR the input key state value with the unreleased key state value, and perform an AND operation with the key state value input this time. When the result of the XOR operation of a certain bit is 1, it is obtained that the pressing state of the bit has changed. By performing an AND operation with the key state value saved this time, it can be obtained which bit represents the key that is triggered by the current pressing.

[0096] Step 303: XOR the input key state value with the unreleased key state value, and then add it to the unreleased key state value. When the result of XOR calculation of a certain bit is 1, it is obtained that the pressing state of the bit has changed, and the key state value that has not been released before is added to the previous value to determine which bit represents the key that was released and triggered this time.

[0097] Step 304: Save the input key state value as an unreleased key state value.

[0098] Step 305 , whether the unreleased key state value is 1, if so, execute step 306 , otherwise execute step 307 .

[0099] Step 306: Accumulate the duration of continuous pressing of the unreleased keys.

[0100] Step 307 : If both the unreleased key state value and the released key state value are 0, execute step 308 ; otherwise, return to execute step 301 .

[0101] Step 308: Clear the continuous pressing time of the unreleased keys.

[0102] Exemplary, combined Figure 5 , taking the key state value keyVal=0x0001 (0x0001 has 16 bits, which is converted into binary as 0000 0000 0000 0001, indicating that the first key on the keyboard is pressed) input this time as an example for explanation.

[0103] A. When the key status value keyVal=0x0001, the current key variable keyTemp=0x0001.

[0104] B. When a key is pressed, the trigger variable keyType.trg = (0x0001^0x0000) & 0x0001 = 0x0001. It should be noted that before the first key is pressed, the unreleased key value variable keyType.cont is 0x0000.

[0105] C. When the key is released, the release trigger variable keyType.release = (0x0000^0x0001) & 0x0001 = 0x0001. It should be noted that before the first key is released, the unreleased key value variable keyType.cont is 0x0001.

[0106] D. Update the unreleased key value variable keyType.cont to the current key variable keyTemp, that is, keyType.cont = keyTemp = 0x0001.

[0107] E. When the key is in a continuous pressing state, keyType.cont = 0x0001, and the continuous pressing duration variable keyType.downCnt begins to accumulate the interval duration of the scheduled sampling period T.

[0108] F. When the key is released, keyType.cont = 0x0000, keyType.release = 0x0000, and the continuous pressing duration in the variable keyType.downCnt is cleared.

[0109] See also Figure 6 , Figure 6 FIG. 1 is a flow chart of another keyboard key state detection method provided in an embodiment of the present application. Figure 6 As shown, the following steps may be included:

[0110] Step 401: Input the key state value of each key on the keyboard.

[0111] Step 402: XOR the input key state value with the unreleased key state value, and perform an AND operation with the key state value input this time. When the result of the XOR operation of a certain bit is 1, it is obtained that the pressing state of the bit has changed. By performing an AND operation with the key state value saved this time, it can be obtained which bit represents the key that is triggered by the current pressing.

[0112] Step 403: XOR the input key state value with the unreleased key state value, and then add it to the unreleased key state value. When the result of XOR calculation of a certain bit is 1, it is obtained that the pressing state of the bit has changed, and the key state value that has not been released before is added to the previous value to determine which bit represents the key that was released and triggered this time.

[0113] Step 404: Save the input key state value as an unreleased key state value.

[0114] Step 405 , whether the unreleased key state value is 1, if so, execute step 406 , if not, execute step 407 .

[0115] Step 406 , cyclically determine whether the current key among all keys is in a continuously pressed state, if so, execute step 408 , otherwise, execute step 409 .

[0116] Step 408: Accumulate the duration of continuous pressing of the current key.

[0117] Step 409: Clear the continuous pressing time of the current key.

[0118] Step 407 : If both the unreleased key state value and the released key state value are 0, execute step 410 ; otherwise, return to execute step 401 .

[0119] Step 410: Clear the continuous pressing time of all keys.

[0120] Exemplary, combined Figure 6 , taking the key status value keyVal = 0x0002 input this time as an example for illustration. (0x0002 has 16 bits, and when converted to binary, it is 0000 0000 0000 0010, indicating that the second key on the keyboard is pressed).

[0121] A. When the key status value keyVal = 0x0002, the current key variable keyTemp = 0x0001.

[0122] B. When a key is pressed, the press trigger variable keyType.trg = (0x0002 ^ 0x0000) & 0x0002 = 0x0002. It should be noted that before the second key is pressed, the non-released key value variable keyType.cont is 0x0000.

[0123] C. When the key is released, the release trigger variable

[0124] keyType.release = (0x0000 ^ 0x0002) & 0x0002 = 0x0002. It should be noted that before the second key is released, the non-released key value variable keyType.cont is 0x0002.

[0125] D. Update the non-released key value variable keyType.cont to the current key variable keyTemp, that is, keyType.cont = keyTemp = 0x0002.

[0126] E. When the key is in a continuous press state, keyType.cont = 0x0002. Through for(i = 0; i < 16; i++), if(keyType.cont & (0x0001 << i)), it can be determined that the second key is in the press state, and i = 2 is obtained. The continuous press duration variable keyType.downCnt[2] starts to accumulate the interval duration of the scheduled sampling period T.

[0127] F. After the key is released, keyType.cont = 0x0000, keyType.release = 0x0000, and all the continuous press durations in the continuous press duration variable keyType.downCnt[i] are cleared.

[0128] It should be noted that in the embodiment of the present application, each bit of the above variables corresponds to a key. The key status corresponding to each bit is calculated by means of bitwise operations to implement the judgment of pressing, releasing, and continuous pressing. And when the key is in a continuous press state, the continuous press duration of the key in the continuous press state is timed separately, without being affected by the pressing or releasing of other keys.

[0129] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. The computer program includes program instructions, and a processor executes the above program instructions to implement any positioning detection method for a computer device provided in an embodiment of the present application.

[0130] For example, the program is loaded by the processor and may execute the following steps:

[0131] Obtain a first key state value of each key in the keyboard at a current sampling time point and a second key state value at a previous sampling time point; perform bitwise operation on the first key state value and the second key state value to determine a trigger operation corresponding to each key; determine a key state detection result of the keyboard according to the trigger operation corresponding to each key, the key state detection result including at least one of the following: a key that is triggered and released, a key that is triggered and pressed, a key that is in a continuously pressed state, and a key that has not triggered an operation.

[0132] The computer-readable storage medium may be an internal storage unit of the computer device of the aforementioned embodiment, such as a hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital card (Secure Digital Card, SD Card), a flash card (Flash Card), etc. equipped on the computer device.

[0133] Furthermore, the computer-readable storage medium may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, programs required for at least one function, etc.; the data storage area may store data created according to each program, etc.

[0134] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A method for detecting the key status of a keyboard, It is characterized in that The method comprises: Obtaining a first key state value of each key in the keyboard at a current sampling time point and a second key state value at a previous sampling time point; Performing a bitwise operation on the first button state value and the second button state value to determine a trigger operation corresponding to each button; According to the trigger operation corresponding to each of the keys, the key state detection result of the keyboard is determined, and the key state detection result includes at least one of the following: a key that is triggered and released, a key that is triggered and pressed, a key that is in a continuously pressed state, and a key that has not triggered an operation.

2. The method for detecting the key status of a keyboard according to claim 1, It is characterized in that The performing a bitwise operation on the first button state value and the second button state value to determine a trigger operation corresponding to each button includes: Determining each of the keys as a target key in turn; Performing an XOR calculation on the first key state value and the second key state value of the target key to obtain an XOR calculation value corresponding to the target key, wherein the XOR calculation value is used to indicate whether the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point; If it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has changed relative to the first key state at the previous sampling time point, then determining the triggering operation of the target key according to the first key state and the second key state; If it is determined according to the XOR calculation value that the second key state of the target key at the current sampling time point has not changed relative to the first key state at the previous sampling time point, the trigger operation of the target key is determined according to the second key state value.

3. The method for detecting the key status of a keyboard according to claim 2, It is characterized in that When the XOR calculation value is the first preset value, the second key state of the target key at the current sampling time point changes relative to the first key state at the previous sampling time point; When the XOR calculation value is a second preset value, the second key state of the target key at the current sampling time point does not change relative to the first key state at the previous sampling time point, wherein the first preset value is different from the second preset value.

4. The method for detecting the key status of a keyboard according to claim 2, It is characterized in that The determining the triggering operation of the target button according to the first button state and the second button state includes: If the first button state is a pressed state and the second button state is a released state, determining that the triggering operation of the target button is a triggering release operation; If the first button state is a released state and the second button state is a pressed state, it is determined that the triggering operation of the target button is a triggering pressing operation.

5. The method for detecting the key status of a keyboard according to claim 2, It is characterized in that The step of determining the triggering operation of the target key according to the second key state value includes: Updating the first button state value according to the second button state value to obtain an updated first button state value; If the updated first button state value is the third preset value, it is determined that the triggering operation of the target button is a continuous pressing operation.

6. The keyboard key state detection method according to any one of claims 1 to 5, It is characterized in that After determining the key state detection result of the keyboard according to the trigger operation corresponding to each key, the method further includes: If there is at least one key in a continuously pressed state on the keyboard, the total continuously pressed duration corresponding to the keyboard is determined and / or the sub-continuous pressed duration corresponding to each key in a continuously pressed state is determined.

7. The method for detecting the key status of a keyboard according to claim 6, It is characterized in that The determining the total continuous pressing time duration corresponding to the keyboard includes: Determine a first number of times that a key of the keyboard is in a continuously pressed state at consecutive sampling time points; The total continuous pressing duration is determined according to the interval between the first number of times and the sampling time point.

8. The method for detecting the key status of a keyboard according to claim 6, It is characterized in that The determining of the sub-continuous pressing duration corresponding to each key in the continuous pressing state includes: sequentially determining each of the keys in a continuously pressed state as a key to be detected; Determine a second number of times that the key to be detected is in a pressed state at consecutive sampling time points; The sub-continuous pressing time duration corresponding to the key to be detected is determined according to the interval between the second number of times and the sampling time point.

9. A computer device, It is characterized in that The computer device includes a memory and a processor; The memory is used to store computer programs; The processor is used to execute the computer program and implement the keyboard key status detection method as described in any one of claims 1 to 8 when executing the computer program.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor implements the keyboard key state detection method according to any one of claims 1 to 8.

Citation Information

Cited By

  • Keyboard key detection method and device and computer storage medium

    CN121435088A

  • Keyboard key detection method, device and computer storage medium

    CN121435088B