Key operation detection method, detection device, electronic device, and storage medium
By storing and retrieving key information in the order of key events and combining it with first-in-first-out queue management, the problem of accuracy in key detection in the case of multiple keys is solved, and efficient recognition of user key operations is achieved.
Patent Information
- Application Number
- CN202210248290.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-14
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2042-03-14
AI Technical Summary
In the existing technology, the key detection logic of electronic devices with multiple keys is complex, which can easily lead to missed or misidentified key events, resulting in inaccurate recognition of user key operations.
By detecting the order in which key events are pressed, key information is stored and retrieved sequentially. A first-in-first-out queue is used to manage key information, ensuring the orderliness and accuracy of key operations.
It effectively avoids the omission and misidentification of key events, and improves the recognition accuracy of user key operations on electronic devices.
Smart Images

Figure CN114637409B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of electronic equipment, and in particular to a key operation detection method, a key operation detection device, an electronic device and a computer readable storage medium. BACKGROUND
[0002] With the development of economy and technology, electronic devices are increasingly widely used. Among them, the operation of most electronic devices needs to use keys to obtain user input instructions. At present, the key detection method is generally to identify the key pressing and releasing of the high and low levels of different key interfaces through a key interrupt processing function, and then to distinguish between long pressing and short pressing of the key through a timer, and to complete the key debouncing function through the delay. In the case of many keys, the running logic is complex, and the level information reading corresponding to different key events is prone to blocking, resulting in missing key events or misidentification of recognized key events, which leads to the inability to accurately identify the user's key operation. SUMMARY
[0003] The main purpose of the present application is to provide a key operation detection method, a key operation detection device, an electronic device and a computer readable storage medium, which aims to improve the accuracy of user key operation recognition on the electronic device.
[0004] To achieve the above purpose, the present application provides a key operation detection method, which comprises the following steps:
[0005] detecting key events and storing the key information corresponding to each detected key event in a first order, wherein the first order is the order in which each key event is detected;
[0006] reading each key information in a second order and determining the key operation according to the key information read in sequence, wherein the second order is the order in which each key information is stored.
[0007] Optionally, the step of detecting key events and storing the key information corresponding to each detected key event in a first order comprises:
[0008] detecting key events and writing the key information corresponding to each detected key event into a first-in-first-out queue in the first order;
[0009] The step of reading each key information in a second order comprises:
[0010] reading each key information in the first-in-first-out queue in the order in which it is written.
[0011] Optionally, the step of sequentially reading each of the key information according to the writing order of each of the key information in the first-in-first-out queue comprises:
[0012] obtaining a first number of the key information currently written in the first-in-first-out queue;
[0013] reading target key information and updating a second number of the key information currently read in the first-in-first-out queue; the target key information is the key information with the first rank in the key information currently not read in the first-in-first-out queue;
[0014] if the second number is less than the first number, determining new target key information according to the writing order, and returning to execute the step of reading target key information and updating a second number of the key information currently read in the first-in-first-out queue;
[0015] if the second number is equal to the first number, ending reading the key information in the first-in-first-out queue.
[0016] Optionally, the key operation detection method further comprises:
[0017] executing the step of detecting the key event and starting timing to obtain a first timing duration;
[0018] when the first timing duration is less than or equal to a first preset clock period, executing the step of sequentially writing each of the key information corresponding to the detected key event into the first-in-first-out queue according to the first order;
[0019] when the first timing duration is greater than the first preset clock period, executing the step of sequentially reading each of the key information according to the writing order of each of the key information in the first-in-first-out queue.
[0020] Optionally, after the step of executing the step of detecting the key event and starting timing to obtain a first timing duration, the method further comprises:
[0021] when the first timing duration is greater than the first preset clock period, starting timing to obtain a second timing duration;
[0022] when the second timing duration is less than or equal to a second preset clock period, executing the step of sequentially reading each of the key information according to the writing order of each of the key information in the first-in-first-out queue;
[0023] when the second timing duration is greater than the second preset clock period, returning to execute the step of detecting the key event and starting timing to obtain a first timing duration.
[0024] Optionally, the key information corresponding to the key event comprises a key identifier, a key event type, and a time of detecting the corresponding key event.
[0025] Optionally, the key information read in sequence comprises first key information and second key information, and the step of determining the key operation according to the key information read in sequence comprises:
[0026] when the first key information and the second key information satisfy a preset condition, determining a time difference between the second time and the first time; the preset condition comprises that the first key information and the second key information both comprise a same target key identifier, the key event type in the first key information is that a key is pressed, and the key event type in the second key information is that the key is released, the first time is a time of detecting the corresponding key event included in the first key information, and the second time is a time of detecting the corresponding key event included in the second key information;
[0027] when the time difference is less than or equal to a set threshold, determining that the key operation is a short press operation of the key corresponding to the target key identifier;
[0028] when the time difference is greater than the set threshold, determining that the key operation is a long press operation of the key corresponding to the target key identifier.
[0029] In addition, in order to achieve the above-mentioned purpose, the application further provides a key operation detection device, which comprises a memory, a processor, and a key operation detection program stored in the memory and executable on the processor, and the key operation detection program realizes the steps of the key operation detection method according to any one of the above-mentioned embodiments when executed by the processor.
[0030] In addition, in order to achieve the above-mentioned purpose, the application further provides an electronic device, which comprises:
[0031] a key module comprising at least two keys;
[0032] The key operation detection device described above, wherein the at least two keys are connected with the key operation detection device.
[0033] In addition, in order to achieve the above-mentioned purpose, the application further provides a computer readable storage medium, which stores a key operation detection program, and the key operation detection program realizes the steps of the key operation detection method according to any one of the above-mentioned embodiments when executed by a processor.
[0034] The key operation detection method provided by the application stores the key information corresponding to each key time in order according to the order of detecting each key event in the process of detecting the key time, further reads each stored key information in order according to the order of storing each key information, and determines the single operation according to the key information read in order, so that the information corresponding to the key event of each key can be recorded in order and accurately even if there are multiple keys on the electronic device, the omission of key events or the misidentification of key events is effectively avoided, and the accuracy of the identification of the user key operation on the electronic device is effectively improved. BRIEF DESCRIPTION OF DRAWINGS
[0035] Figure 1 The hardware structure schematic diagram related to the operation of an embodiment of the electronic device of the application is shown in the figure.
[0036] Figure 2 The flowchart schematic diagram of an embodiment of the key operation detection method of the application is shown in the figure.
[0037] Figure 3 The flowchart schematic diagram of another embodiment of the key operation detection method of the application is shown in the figure.
[0038] Figure 4 The flowchart schematic diagram of another embodiment of the key operation detection method of the application is shown in the figure.
[0039] Figure 5 The writing and reading process schematic diagram of the key information in the first-in-first-out queue related to the embodiment of the key operation detection method of the application is shown in the figure.
[0040] Figure 6 The flowchart schematic diagram of another embodiment of the key operation detection method of the application is shown in the figure.
[0041] The implementation, functional features and advantages of the application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0042] It should be understood that the specific embodiments described herein are merely intended to explain the application, and are not intended to limit the application.
[0043] The main solution of the embodiment of the application is to detect the key event, and store the key information corresponding to each detected key event in order according to a first order, the first order being the order of detecting each key event; read each key information in order according to a second order, and determine the key operation according to the key information read in order, the second order being the order of storing each key information.
[0044] In the prior art, the key detection mode is generally to recognize the high and low levels of different key interfaces by a key interrupt processing function to identify the key being pressed and released, and then to distinguish the long press or short press of the key by a timer, and to complete the key debouncing function by the delay. In the case of many keys, the running logic is complex, and the level information reading corresponding to different key events is easy to block, resulting in missing key events or misidentification of key events, and thus the user's key operation cannot be accurately identified.
[0045] The present application provides the above-mentioned solution, aiming to improve the accuracy of user key operation identification on an electronic device.
[0046] An embodiment of the present application provides a key operation detection device 1, which can be applied to detect the key operation on an electronic device. Here, the electronic device can be any electronic device provided with keys, such as smartwatches, smartbands, head-mounted display devices, smart earphones, smart speakers, mobile phones, robots, etc. In this embodiment, the key specifically refers to a physical key. In other embodiments, the key can also be a virtual key.
[0047] The key operation detection device 1 can be a device connected to the electronic device, or a device built-in the electronic device.
[0048] In this embodiment of the present application, referring to Figure 1 , the key operation detection device 1 includes a processor 1001 (such as a CPU), a memory 1002, a timer 1003, etc. The components in the key operation detection device are connected through a communication bus. The memory 1002 can be a high-speed RAM memory, or a stable memory (non-volatile memory) such as a disk memory. The memory 1002 can also be an optional storage device independent of the aforementioned processor 1001.
[0049] In this embodiment, the timer 1003 is a tick timer.
[0050] Those skilled in the art can understand that Figure 1 the device structure shown in the above embodiment does not constitute a limitation on the device, and can include more or fewer components than those shown in the figure, or combine certain components, or different component arrangements.
[0051] As shown in Figure 1 , the memory 1002 as a computer readable storage medium can include a key operation detection program. In the device shown in Figure 1 , the processor 1001 can be used to call the key operation detection program stored in the memory 1002, and perform the related step operations of the key operation detection method in the following embodiments.
[0052] Further, the embodiment of the present application also provides an electronic device. The electronic device can be any electronic device provided with the key 2, such as a smart watch, a smart bracelet, a head-mounted display device, a smart earphone, a smart speaker, a mobile phone, a robot, and the like.
[0053] It should be noted that in the embodiment, the electronic device is a device provided with an embedded system.
[0054] With reference to Figure 1 , the electronic device comprises the key operation detection apparatus 1 and at least two keys 2. The at least two keys 2 are connected to the key operation detection apparatus 1. In the embodiment, the key 2 specifically refers to a physical key. In other embodiments, the key 2 can also be a virtual key. The key operation detection apparatus 1 can detect the key operation of the at least two keys 2 according to the key operation detection method mentioned in any one of the following embodiments.
[0055] The embodiment of the present application also provides a key operation detection method applied to the key operation detection apparatus to detect the key operation of the user on the electronic device. It should be noted that the key operation detection method of the embodiment of the present application is mainly used for the key operation detection of the electronic device provided with at least two keys. In other embodiments, the key operation detection method of the embodiment of the present application can also be applied to the key operation detection of the electronic device provided with one key.
[0056] With reference to Figure 2 , an embodiment of the key operation detection method is provided. In the embodiment, the key operation detection method comprises the following steps.
[0057] In step S10, a key event is detected, and the key information corresponding to each detected key event is stored in sequence according to a first sequence. The first sequence is the sequence in which each key event is detected.
[0058] The key event specifically refers to an action event triggered by the key operation of the user. The key event specifically includes the key being pressed and the key being released.
[0059] After the electronic device is powered on or the electronic device runs a preset mode, the key signal output by each key is detected in real time, and the key event of each key is determined according to the key signal.
[0060] The key information corresponding to each detected key event is determined and stored. The key information corresponding to the key event detected first is stored in a preset position first, and the key information corresponding to the key event detected later is stored in the preset position later. The preset position specifically refers to a storage area preset for storing the key information to be identified.
[0061] If there is a key event of detecting different keys at the same time, the key information corresponding to the key event detected at the same time can be stored in the preset order between the keys in sequence, and then the step of storing the key information of each detected key event in the first order is executed again. If there is no key event of detecting different keys at the same time, the step of storing the key information of each detected key event in the first order is maintained. The preset order can be a system default order or an order set by a user according to his own operation habit.
[0062] The key information is information related to a key event and used for key operation recognition. Each key event has a corresponding key information. The key information corresponding to different key events is different. In the embodiment, the key information corresponding to a key event includes a key identifier, a key event type and a time of detecting the corresponding key event. The key identifier is a unique identifier used to distinguish the corresponding key from other keys, which can be a key name or a key number. The key event type includes a first type representing that the corresponding key is pressed down and a second type representing that the corresponding key is released. The time of detecting the key event is the time when the key event occurs. In other embodiments, in addition to the key identifier, the key event type and the time of detecting the corresponding key event, the key information can also include a control code corresponding to the key event, for example, the control code of key 1 being pressed down is a, and the control code of key 2 being released is b.
[0063] In step S20, each key information is read in sequence according to a second order, and a key operation is determined according to the key information read in sequence, wherein the second order is the order of storing each key information.
[0064] The key operation is an operation of a user on a key for inputting a target instruction to an electronic device.
[0065] Specifically, in the process of step S10, timing can be started when a key event is detected, and step S20 can be executed when the timing duration is greater than a set duration and no next key event is detected. Alternatively, timing can be started when a key event is detected, and step S20 can be executed when the timing duration reaches a preset period. Alternatively, in the process of step S10, the number of stored key information is counted, and step S20 can be executed when the number of key information is greater than a set number. The set number is less than or equal to the maximum number of key information allowed to be stored in the preset position.
[0066] Specifically, the stored key information is read first, and the stored key information is read later. Specifically, the key information read first and later is parsed according to the recognition rule of the key operation to obtain the operation corresponding to the read key information. The key operation here can be one or more than one, and when the key operation is more than one, it can include the key operation corresponding to different keys or more than one key operation corresponding to the same key.
[0067] The key operation detection method provided in the embodiment of the application stores the key information corresponding to each key time in turn according to the order of detection of each key event in the process of detecting the key time, further reads each stored key information in turn according to the order of storage of each key information, and determines the single operation according to the key information read in turn. In this process, even if there are multiple keys on the electronic device, the information corresponding to the key event of each key can be recorded in order and accurately, effectively avoiding missing key events or misidentifying key events, thereby effectively improving the accuracy of user key operation recognition on the electronic device.
[0068] Further, based on the above embodiment, another embodiment of the key operation detection method of the application is provided. In this embodiment, referring to Figure 3 , the step S10 includes:
[0069] Step S11, detecting a key event, and writing the key information corresponding to each detected key event in the first order into a first-in first-out queue in turn;
[0070] Based on step S11, step S20 includes:
[0071] Step S21, reading each key information in the first-in first-out queue in turn according to the writing order of each key information in the first-in first-out queue.
[0072] The first-in first-out queue is a data structure that performs data insertion and deletion based on first-in first-out. The first-in first-out queue can specifically determine the maximum number of elements allowed to be stored according to the number of keys on the electronic device.
[0073] The key information corresponding to each detected key event can be written as a new element at the tail of the queue, and the position of the key information corresponding to the detected key event in the queue is earlier than the position of the key information corresponding to the later detected key event in the queue.
[0074] When reading the key information, the key information is read from the queue in turn according to the position in the queue.
[0075] In the embodiment, the first-in first-out queue is used for storing and reading the key information, so as to further ensure the orderliness and accuracy of the key information detection in the key operation recognition process, and to further improve the accuracy of the user key operation recognition on the electronic device. Moreover, the reading of the key information can be performed in a non-blocking manner by using the first-in first-out queue for storing and reading the key information, and the reading of the key information does not need to wait for the completion of the key jitter filtering process, so as to further improve the orderliness and accuracy of the key information detection, and to further improve the accuracy of the user key operation recognition.
[0076] Further, in the embodiment, the key operation detection method further includes: performing the step of detecting the key event and starting timing to obtain a first timing duration; when the first timing duration is less than or equal to a first preset clock period, performing the step of sequentially writing the key information corresponding to each detected key event into the first-in first-out queue according to the first sequence; when the first timing duration is greater than the first preset clock period, performing the step of sequentially reading each key information according to the writing sequence of the key information in the first-in first-out queue.
[0077] The first preset clock period can be determined according to the type of all allowed key operations of the electronic device, the number of keys on the electronic device, and / or the maximum number of allowed storage elements of the first-in first-out queue, etc. Different key operation types, different key numbers, and / or different maximum allowed storage numbers correspond to different first preset clock periods.
[0078] When the first timing duration does not reach the first preset clock period, the key event is continuously detected, and the key information of the detected key event is sequentially written into the first-in first-out queue according to the detection sequence; when the first timing duration exceeds the first preset clock period, the key information is sequentially read according to the writing sequence.
[0079] In which, after each reading of a key information, the key information can be deleted from the head of the first-in first-out queue to ensure that the number of elements stored in the first-in first-out queue does not exceed the maximum allowed number; or, the key information in the first-in first-out queue can also be deleted after reading all the information in the first-in first-out queue. In addition, during the reading of the key information, the key event can be detected, and the key information of the newly detected key event can be written into the tail of the first-in first-out queue, and if the number of key information currently written into the first-in first-out queue has reached the maximum allowed number, the head of the current first-in first-out queue can be used as a new tail.
[0080] In the embodiment, the first preset clock period is used to limit the trigger timing of starting reading the key information, so that the storage and writing process of the key information is prevented from being blocked, and the accuracy of recognizing the user key operation on the electronic device is further improved. Moreover, the reading of the key information can be periodically performed in the tick timer, and it is not necessary to detect in the main program all the time, so that the resource consumption of the embedded system is reduced.
[0081] Further, after the step of detecting the key event and starting timing to obtain the first timing duration, the embodiment further includes: when the first timing duration is greater than the first preset clock period, starting timing to obtain a second timing duration; when the second timing duration is less than or equal to a second preset clock period, performing the step of reading each key information in the first-in-first-out queue according to the writing order of the key information; and when the second timing duration is greater than the second preset clock period, returning to perform the step of detecting the key event and starting timing to obtain the first timing duration.
[0082] The second preset clock period can be determined according to the first preset clock period, the type of all the key operations allowed to exist in the electronic device, the number of keys on the electronic device, and / or the maximum number of elements allowed to be stored in the first-in-first-out queue.
[0083] The key information in the first-in-first-out queue is continuously read according to the second order when the second timing duration does not reach the second preset clock period, and the key event is detected again when the second timing duration exceeds the second preset clock period.
[0084] In the embodiment, the second preset clock period is used to limit the reading duration of the key information and the timing of triggering the next key operation detection, so that the storage and writing process of the key information is prevented from being blocked, and different key operations of the user can be accurately distinguished, thereby further improving the accuracy of recognizing the user key operation on the electronic device. Moreover, the reading and writing of the key information can be periodically performed in the tick timer, and it is not necessary to detect in the main program all the time, so that the resource consumption of the embedded system is reduced.
[0085] Further, based on any of the above embodiments, another embodiment of the key operation detection method is provided. In the embodiment, referring to Figure 4 , the step S21 includes:
[0086] In the step S211, the first number of the key information currently written in the first-in-first-out queue is obtained.
[0087] Specifically, the pre-set identification value is used to represent the number of the currently written key information in the first-in first-out queue. The initial value of the identification value is 0. The value of the identification value is increased by 1 each time a key information is written in the first-in first-out queue, and the value of the identification value is decreased by 1 each time a key information is deleted from the first-in first-out queue.
[0088] Based on this, reading the current identification value can obtain the first number here.
[0089] Step S212, reading the target key information and updating the second number of the currently read key information in the first-in first-out queue; the target key information is the key information with the first rank in the key information not read in the first-in first-out queue;
[0090] The second number is updated once each time a key information in the first-in first-out queue is read. Specifically, the reading of the target key information is completed before and after the information in the first-in first-out queue is read, and then the current second number is increased by 1 to obtain the updated second number.
[0091] Step S213, if the second number is less than the first number, determining a new target key information according to the writing order, and returning to execute the step of reading the target key information and updating the second number of the currently read key information in the first-in first-out queue;
[0092] Specifically, the key information with the rank one position after the current rank in the first-in first-out queue is taken as the new target key information, and then the new target key information is read and the second number is further updated.
[0093] Step S214, if the second number is the first number, ending the reading of the key information in the first-in first-out queue.
[0094] After step S214, the key operation can be determined according to all the key information read at present.
[0095] Further, after step S214, the step of detecting the key event and storing the key information corresponding to each detected key event in the first order can be returned to be executed. Further, after step S214, the step of detecting the key event and starting the timing to obtain the first timing duration can be returned to be executed.
[0096] In order to better understand the technical solutions designed in the embodiment, the following will be combined with Figure 5 Taking a first-in first-out queue of five units as an example for description:
[0097] The Write variable represents the writing position, and the Read variable represents the reading position. In the initial state, as shown in FIG. 2, the first-in first-out queue is empty, and the Write variable and the Read variable are both 0. Figure 5As shown in (a), Read = Write = 0, and null in the FIFO queue indicates that no key information has been written. If keys K1 and K2 are pressed sequentially, the key information for the events of K1 pressed, K1 released, K2 pressed, and K2 released is stored sequentially in the FIFO queue, and the data in the FIFO queue becomes... Figure 5 (b). Among them, K1 and K2 represent button identifiers, Up represents the button being released and Down represents the button being pressed.
[0098] Each time a key press is read from the FIFO queue, `Read` is incremented by 1, and `Write` remains unchanged; each time a key press is stored in the FIFO queue, `Read` remains unchanged, and `Write` is incremented by 1. For example, from... Figure 5 In (b), when reading a key press from the FIFO queue, Read becomes 1, while Write remains unchanged at 4. When reading three more key presses from the FIFO queue, Read becomes 4, while Write remains unchanged at 4. At this point, the two variables are equal, indicating that all key presses have been processed and no new key presses are being processed. Key presses can then continue to be detected until new key presses are written to the FIFO queue.
[0099] In this embodiment, by using the above method, it can be ensured that no key information corresponding to the key press time is missed during the key operation recognition process, thereby further improving the accuracy of key operation recognition.
[0100] Furthermore, based on any of the above embodiments, another embodiment of the key operation detection method of this application is proposed. In this embodiment, any two key information read sequentially are defined as the first key information and the second key information, respectively, referring to... Figure 6 Step S30 includes:
[0101] Step S31: When the first key information and the second key information meet preset conditions, determine the time difference between the second time and the first time; the preset conditions include that the first key information and the second key information both include the same target key identifier, the key event type in the first key information is key pressed and the key event type in the second key information is key released, the first time is the time when the corresponding key event is detected in the first key information, and the second time is the time when the corresponding key event is detected in the second key information;
[0102] Step S32: When the time difference is less than or equal to a set threshold, it is determined that the key operation is a short press operation of the key corresponding to the target key identifier;
[0103] Step S33, when the time difference value is greater than the set threshold value, determining that the key operation is a long press operation of the key corresponding to the target key identifier.
[0104] For example, the read key information has 4, in turn, K1 Down T1, K1 Up T2, K2 Down T3, K2 Up T4, wherein, K1, K2 represents the key identifier, Up represents the key release key event, Down represents the key press key event, T1, T2, T3, T4 are the occurrence time corresponding to each key event. Based on this, the first key information and the second key information of the key identifier are K1, and the first detected first key information contains the information of the key press, and the second detected second key information contains the information of the key release, then according to the comparison of T2-T1 and the set threshold value, the key operation of K1 key is long press or short press; the key identifier of the third key information and the fourth key information is K2, and the third detected third key information contains the information of the key press, and the fourth detected fourth key information contains the information of the key release, then according to the comparison of T4-T3 and the set threshold value, the key operation of K2 key is long press or short press.
[0105] In the embodiment, by the above-mentioned manner, the long press operation and the short press operation of different keys can be accurately distinguished, so that the accuracy of the key operation recognition of the keys with different key lengths on the electronic device is improved.
[0106] In addition, the embodiment of the present application also provides a computer readable storage medium, and the computer readable storage medium stores a key operation detection program. When the key operation detection program is executed by a processor, the related steps of any one of the above key operation detection methods are realized.
[0107] It should be noted that in this paper, the term "including", "containing" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or system including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or includes elements inherent to such process, method, article or system. Without more limitation, the element defined by the statement "including a" does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0108] The above-mentioned serial numbers of the embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.
[0109] Those skilled in the art can clearly understand the above-mentioned embodiment method can be realized by means of software and the necessary general hardware platform, of course, also can be through hardware, but in many cases the former is the better embodiment. Based on such understanding, the technical solutions of the present application essentially or say the part of the prior art contribution can be embodied in the form of software products, the computer software product is stored in a storage medium (such as ROM / RAM, magnetic disc, optical disc) as described above, including a number of instructions to make a terminal device (may be a mobile phone, computer, server, electronic device, or network equipment, etc.) executes the method described in various embodiments of the present application.
[0110] The above is only the preferred embodiment of the present application, not therefore limit the patent scope of the present application, any equivalent structure or equivalent flow transformation made by using the content of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for detecting key operation, characterized in that, The key operation detection method includes the following steps: The steps of detecting key events and storing the key information corresponding to each detected key event in a first order include: detecting key events and writing the key information corresponding to each detected key event into a first-in-first-out queue in a first order. The first order is the order in which each key event is detected, wherein the key signal output by each key is detected in real time, and the key event of each key is determined based on the key signal; The steps of reading each key information in the second order include: reading each key information in the order of writing the key information in the first-in-first-out queue; The button operation is determined based on the button information read in sequence. The second order is the order in which each button information is stored. The button information includes a button identifier, a button event type, and the time when the corresponding button event is detected. The button operation includes a long press or a short press. Define any two sequentially read key information as the first key information and the second key information, and the step of determining the key operation based on the sequentially read key information includes: When the first key information and the second key information meet preset conditions, the time difference between the second time and the first time is determined; the preset conditions include that the first key information and the second key information both include the same target key identifier, the key event type in the first key information is that the key is pressed and the key event type in the second key information is that the key is released, the first time is the time when the corresponding key event is detected in the first key information, and the second time is the time when the corresponding key event is detected in the second key information. When the time difference is less than or equal to a set threshold, it is determined that the key operation is a short press operation of the key corresponding to the target key identifier; When the time difference is greater than the set threshold, it is determined that the key operation is a long press operation of the key corresponding to the target key identifier; The key operation detection method further includes: Perform the steps to detect the key event and start timing to obtain the first timing duration; When the first timing duration is less than or equal to the first preset clock cycle, the step of writing the key information corresponding to each detected key event into the first-in-first-out queue according to the first order is executed. When the first timing duration is greater than the first preset clock cycle, the step of sequentially reading each key information according to the writing order of each key information in the first-in-first-out queue is executed.
2. The key operation detection method as described in claim 1, characterized in that, The step of sequentially reading each key information according to the writing order of each key information in the first-in-first-out queue includes: Obtain the first number of key presses currently written in the first-in-first-out queue; Read the target key information and update the second number of key information currently read in the first-in-first-out queue; the target key information is the key information with the highest position among the key information currently not read in the first-in-first-out queue. If the second quantity is less than the first quantity, then new target key information is determined according to the writing order, and the process of reading the target key information and updating the second quantity of key information currently read in the first-in-first-out queue is returned. If the second quantity is the same as the first quantity, the reading of key information in the first-in-first-out queue ends.
3. The key operation detection method as described in claim 1, characterized in that, After performing the steps of detecting key events and starting the timer to obtain the first timing duration, the method further includes: When the first timing duration is greater than the first preset clock cycle, timing begins to obtain the second timing duration; When the second timing duration is less than or equal to the second preset clock cycle, the step of sequentially reading each key information according to the writing order of each key information in the first-in-first-out queue is executed. When the second timing duration is greater than the second preset clock cycle, return to the step of executing the detected button event and starting timing to obtain the first timing duration.
4. A button operation detection device, characterized in that, The key operation detection device includes: a memory, a processor, and a key operation detection program stored in the memory and executable on the processor. When the key operation detection program is executed by the processor, it implements the steps of the key operation detection method as described in any one of claims 1 to 3.
5. An electronic device, characterized in that, The electronic device includes: A button module, wherein the button module includes at least two buttons; The button operation detection device as described in claim 4, wherein the at least two buttons are connected to the button operation detection device.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a key operation detection program, which, when executed by a processor, implements the steps of the key operation detection method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Method and device for detecting keyboard key values
CN105634503A
Key identification method and device, equipment and storage medium
CN113114268A