WM_KEYDOWN and multiple keys

This is a discussion on WM_KEYDOWN and multiple keys within the Windows Programming forums, part of the Platform Specific Boards category; Is there a way to handle the WM_KEYDOWN message (or any other message) in order to know every key that ...

  1. #1
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916

    WM_KEYDOWN and multiple keys

    Is there a way to handle the WM_KEYDOWN message (or any other message) in order to know every key that is being held down on the keyboard? (two arrow keys, for example)
    Away.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227

  3. #3
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Due to a limitation of the hardware (which depends on what keyboard you have hooked up), it only reports a certain maximum number of keys. This number is dependant on which keys are being held down, and it what order - so it is variable. I used to have a key scanner program in DOS that demonstrated this very well, but I don't have it with me at the moment. If I remember, I'll attach it to the thread, since I believe it still works perfectly from within windows. You may want to code one of these yourself, just to see the limitations. Basically, show an on/off state for every key scan code... pretty simple.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    GetKeyboardState() puts the status of all the keys into an array. The index is the virtual key codes.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    Please note the difference between the two:

    GetKeyboardState(): Retrieves the current status of all the virtual keys. The status changes as a thread removes keyboard messages from its message queue. The status does not change as keyboard messages are posted to the thread's message queue, nor does it change as keyboard messages are posted to or retrieved from message queues of other threads.

    GetAsyncKeyState(): Retrieves the current state for an individual key regardless of whether the corresponding keyboard message has been retrieved from the message queue. It determines whether a key is up or down at the time the function is called.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21