Let's start by explaining what happens when you press a keyboard to not release: Multiple pressed messages are generated, and the content of the message is the same as the key you pressed.
Implementation of long-press time to execute multiple times: for example, you long press the "A" button, you can make the interface of a control of the value has been increased, then you just in the implementation of this button in response to the event to increase one time, as long as you press, automatically will call you many times this function.
Implement long press execution once: this according to the Internet, you can add a static variable to record which key was last pressed. The main code is as follows
(1) Adding a static variable to a class
Private
Static WPARAM Last_key;
(2) The value of the initialization variable in the source file is a non-keyboard value for the first keystroke response
WPARAM Crobotclientdlg::last_key =-1;
(3) In response to the time button press the time to determine whether to press the first time
if (Wm_keydown = = pmsg->message)
if (Pmsg->wparam = = Vk_left && pmsg->wparam! = Last_key)
{
Last_key = pmsg->wparam;
DoSomething
}
Release the Control key
if (Wm_keyup = = pmsg->message)
if (M_use_keyboard_contrl = = True && Pmsg->wparam = = vk_left)
{
Last_key =-1;
DoSomething
}
Note that there are several bugs that you might write to
(1) If you do not reply to the Last_key mark when you release the button, then you have to control the keyboard to perform a number of times can be executed only once, because there are no other keys in the meantime will change the value of Last_key
(2) If Last_key is set to a static variable of a function, it should also be possible, because the static variable of the function is initialized only once, and the subsequent sentence is not executed.
MFC keyboard long press executes multiple times and executes once