Using arrow keys, two keys at once
-
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
-
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
-
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
-
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
You may poll what keys are pressed by calling
::GetAsyncKeyState( <virtual key code> )
. For virtual key codes you can useVK_LEFT
,VK_RIGHT
,VK_UP
andVK_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 -
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
WM_KEYDOWN
orWM_KEYUP
isnt helpfuls?
WhiteSky
-
You may poll what keys are pressed by calling
::GetAsyncKeyState( <virtual key code> )
. For virtual key codes you can useVK_LEFT
,VK_RIGHT
,VK_UP
andVK_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 -
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
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. that1100
in binary equals0xC
in hex which equals12
in decimal.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown