Search code examples
c++winapikeyboardraw-input

Looking for key-repeat data in WM_INPUT message


I just started using Raw Input for my app. Getting straight to the question, in the legacy WM_KEYDOWN messages, the lParam could be checked to obtain extra information about the key press. Like these-

 Bits   Meaning
    0-15    The repeat count for the current message. 
            The value is the number of times the keystroke is autorepeated as a         
            result of the user holding down the key. If the keystroke is 
            held long enough, multiple messages are sent. However, the repeat 
            count is not cumulative.
   16-23    The scan code. The value depends on the OEM.
   24       Indicates whether the key is an extended key, such as the right-hand
            ALT and CTRL keys that appear on an enhanced 101- or 102-key 
            keyboard. The value is 1 if it is an extended key; otherwise, it is
            0.
   25-28    Reserved; do not use.
   29       The context code. The value is always 0 for a WM_KEYDOWN message.
   30       The previous key state. The value is 1 if the key is down before the
            message is sent, or it is zero if the key is up.
   31       The transition state. The value is always 0 for a WM_KEYDOWN
            message.

I want to know if a WM_INPUT message is for a repeated key, so that I can ignore that message.(turn off keyrepeat.)

The trouble I am having is that this information can't be found for the WM_INPUT message. the lParam of the WM_INPUT message contains the handle to a RAWINPUT structure. On doing some research, I found that inside RAWINPUT::header contains a member called wparam in it and MSDN describes it as

wParam Type: WPARAM The value passed in the wParam parameter of the WM_INPUT message.

Will I find the required information in here or is it somewhere else?


Solution

  • The RAW Input API does not provide repeat counts. It is raw data coming from the keyboard directly. The repeat count is calculated at a higher level when the WM_KEY... messages are generated. Using WM_INPUT, you will have to manually keep track of the down/up states of each key to determine their repeat counts yourself. When a key goes down, start counting each WM_INPUT message for that key. When the key goes up, stop counting it.