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. Using arrow keys, two keys at once

Using arrow keys, two keys at once

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpc++visual-studio
7 Posts 4 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.
  • J Offline
    J Offline
    Johpoke
    wrote on last edited by
    #1

    I made a simple program which when you press the up key shows up, left key shows left etc. But how can i make it work with two keys at once? Like up and right (which would then display up and right..) Is there some not too hard way to do this? thanks all! (MS Visual studio 6, program is a windows console application with mfc)

    //Johannes

    K R 2 Replies Last reply
    0
    • J Johpoke

      I made a simple program which when you press the up key shows up, left key shows left etc. But how can i make it work with two keys at once? Like up and right (which would then display up and right..) Is there some not too hard way to do this? thanks all! (MS Visual studio 6, program is a windows console application with mfc)

      //Johannes

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      AFAIK, you will get one event when a key is pressed and another event when the key is released. Get those events and keep track of what key(s) are currently pressed.

      Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

      J 1 Reply Last reply
      0
      • K kakan

        AFAIK, you will get one event when a key is pressed and another event when the key is released. Get those events and keep track of what key(s) are currently pressed.

        Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

        J Offline
        J Offline
        Johpoke
        wrote on last edited by
        #3

        with what function do i get that? ive tried _getch, but it only catches one of the keys as some keys some dominant over others. thanks

        //Johannes

        H 1 Reply Last reply
        0
        • J Johpoke

          I made a simple program which when you press the up key shows up, left key shows left etc. But how can i make it work with two keys at once? Like up and right (which would then display up and right..) Is there some not too hard way to do this? thanks all! (MS Visual studio 6, program is a windows console application with mfc)

          //Johannes

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

          You may poll what keys are pressed by calling ::GetAsyncKeyState( <virtual key code> ). For virtual key codes you can use VK_LEFT, VK_RIGHT, VK_UP and VK_DOWN for the arrow keys.


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

          J 1 Reply Last reply
          0
          • J Johpoke

            with what function do i get that? ive tried _getch, but it only catches one of the keys as some keys some dominant over others. thanks

            //Johannes

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            WM_KEYDOWN or WM_KEYUP isnt helpfuls?


            WhiteSky


            1 Reply Last reply
            0
            • R Roger Stoltz

              You may poll what keys are pressed by calling ::GetAsyncKeyState( <virtual key code> ). For virtual key codes you can use VK_LEFT, VK_RIGHT, VK_UP and VK_DOWN for the arrow keys.


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

              J Offline
              J Offline
              Johpoke
              wrote on last edited by
              #6

              GetAsyncKeyState(); seems to work perfectly so far! thanks all of you!!! Just a quick question: i can do int data = 0xF; but how do i do the same thing with binary?

              //Johannes

              R 1 Reply Last reply
              0
              • J Johpoke

                GetAsyncKeyState(); seems to work perfectly so far! thanks all of you!!! Just a quick question: i can do int data = 0xF; but how do i do the same thing with binary?

                //Johannes

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

                Johpoke wrote:

                i can do int data = 0xF; but how do i do the same thing with binary?

                In short: you can't. You may write integer values in your source code using decimal, octal or hexadecimal notation. For decimal notation you have no prefix and use digits from 0 to 9, e.g. 255. For octal notation you prefix the number with '0' and use digits from 0 to 7, e.g. 0377. For hexadecimal notation you prefix the number with '0x' and use digits from 0 to F, e.g. 0xFF. Each example represents the same value but with different notations. Regarding how to read and interpret the hexadecimal notation... Each digit represents four bits, a nibble, which can hold values between 0 and 15. You simply have to get it into your spinal cord how to represent a nibble using the different notations, e.g. that 1100 in binary equals 0xC in hex which equals 12 in decimal.


                "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