Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. getting two keys from keyboard simultaneously

getting two keys from keyboard simultaneously

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    V_shr
    wrote on last edited by
    #1

    HI I want to get two keys from the keyboard simultaneously , I mean when you press and hold two keys the kbhit() and getch() functions return only the first pressed key . thanks

    R 1 Reply Last reply
    0
    • V V_shr

      HI I want to get two keys from the keyboard simultaneously , I mean when you press and hold two keys the kbhit() and getch() functions return only the first pressed key . thanks

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      V_shr wrote:

      I want to get two keys from the keyboard simultaneously

      This is impossible since the link from the keyboard is serial. The only way to detect if two keys are pressed simultaniously is if one of them is a shift-key or similar since that would have an impact on the scan code.


      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      D 1 Reply Last reply
      0
      • R Roger Stoltz

        V_shr wrote:

        I want to get two keys from the keyboard simultaneously

        This is impossible since the link from the keyboard is serial. The only way to detect if two keys are pressed simultaniously is if one of them is a shift-key or similar since that would have an impact on the scan code.


        "It's supposed to be hard, otherwise anybody could do it!" - selfquote
        "High speed never compensates for wrong direction!" - unknown

        D Offline
        D Offline
        Dustin Henry
        wrote on last edited by
        #3

        That is incorrect. The GetAsyncKeyState() function will return the status of any key on the keyboard, up or down. You can use this macro: #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) to determine if a key is currently being pressed. This will check key state even if your application does not have focus. If you are actually wanting to capture the key presses, you would actually have loop through all of the key codes and check individual status with this method. Dustin

        R 1 Reply Last reply
        0
        • D Dustin Henry

          That is incorrect. The GetAsyncKeyState() function will return the status of any key on the keyboard, up or down. You can use this macro: #define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) to determine if a key is currently being pressed. This will check key state even if your application does not have focus. If you are actually wanting to capture the key presses, you would actually have loop through all of the key codes and check individual status with this method. Dustin

          R Offline
          R Offline
          Roger Stoltz
          wrote on last edited by
          #4

          Dustin Henry wrote:

          That is incorrect.

          What is incorrect? Whether the link to the keyboard is serial or not isn't a matter of opinion. I guess I misinterpreted the OP's problem and what he meant with "simultaneously". If the question is "how can I determine what keys are being held down", then the answer is "poll the keys with ::GetAsyncKeyState()", like you suggested.


          "It's supposed to be hard, otherwise anybody could do it!" - selfquote
          "High speed never compensates for wrong direction!" - unknown

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups