-
Arrow Keys and Such
Ok I've noticed this on a number of games over the past few years.
The 4 arrows keys are different then the arrow keys on the numpad (when numlock is off), and the number keys over the QWERTYUIOP line is different from the number keys on the numpad (when numlock is on).
Anyone know how this is done? I'm trying to do it in C. Is C just too old to do that?
I've tried to see if there were any differences in values between the two sets but I couldn't find any.
Just wondering. Thanks for any info.
-
ok heres the deal,
when NumLock is on the key pad keys = numbers so that key 1 = 1 and ect ect, other wise the = exactly so... well heres a list
Key = Key Equilivent
NumLock on:
1 = 1,
2 = 2,
3 = 3,
4 = 4,
5 = 5,
6 = 6,
7 = 7,
8 = 8,
9 = 9,
0 = 0.
Key = Function Equilivent
NumLock off;
1 = End
2 = Down Arrow
3 = Page Down
4 = Left Arrow
5 = ?/Nothing
6 = Right Arrow
7 = Home
8 = Up Arrow
9 = Page Up
0 = Insert
-
They ARE different keys, but the keyboard handler you use will convert them to the same key value.
The values that you obtain as keypresses are NOT the values sent by the keyboard to the computer -- there's preprocessing by the keyboard handler. If you wrote your own handler, you would find that pressing the 8/Up key on the keypad would have its own scan code, which is not the same as the scan code for the '8' key or the 'up' key.
In windows, you actually can take the second param to the WM_KEYDOWN message and obtain the actual scancode for the key. The param most people use, the virtual key code, is created by Windows by mapping scancodes to keycodes.
-
Ok I understand what your saying The V. Now to figure out how to build a keyboard handler :)
-
That works just fine, buuuut:
1) You can't run a program that installs its own handler except under true DOS. Windows, if running, will barf if you try to "steal" keyboard handling from it.
2) Keyboard handlers are highly system-dependant, as are the scancodes of keys.
So, when you need to do keyboard handling like this, you need to look at targetting this to only one OS.
Code:
If you are using Then use
-------------------- -------------
DOS/Win3.1 Custom keyboard handler
Win32 DirectInput or WM_KEYDOWN parameter extraction
Unix/Linux ??? -- almost certainly depends on hardware + software
-
well, I think that when you press one of the arrow keys two ASCII codes are sent, the first one is 0, the other ones are:
82: INSERT
83: DELETE
71: HOME
79: END
73: PAGE UP
81: PAGE DOWN
72: UP
80: DOWN
75: LEFT
77: RIGHT
59 - 68: F1 - F10
I can't remember which are the F11 and F12 keys, but I don't think that you will need them ;)
Oskilian