View Full Version : Keyboard Key Codes in VC++...
Hi Everyone...Could you please tell me where I may be able to locate a listing of all the different values for the different keys on the keyboard? What I would like to do is write a program which uses the arrow keys but I do not know the values that the arrow keys take on. ie. the 'ESC' key is '27'...Can you guide me?
All keys except the letters and numbers, I think, got a #define in a header file. It can be windows.h or windefs.h (which is included from windows.h), look in there. They are called VK_<name>, where name is the keyname. Like VK_SPACE, VK_ESCAPE. In MSVC you can type one of these names, right click with the mouse on it, and select something similar to "Go to definition of...", and you will be transported to the definitions.
With the letters you can just type the upper case version of the letter enclosed within a '-pair. Same with numbers, so no need to look up keycodes.
Thanks A Lot...I didn't think about checking the Header files for info! http://www.opengl.org/discussion_boards/ubb/cool.gif http://www.opengl.org/discussion_boards/ubb/smile.gif
I just checked the header files which came with my version of VC++ v.6 and I cannot find any mention of what the keyboard key codes are. Is there a web-site which could help me find out this information?
10-07-2000, 11:05 AM
The virtual key keycodes are defined in the WinUser.h file.
10-07-2000, 12:10 PM
I can't seem to figure out the code for ','/'<' '.'/'>' and '/'/'?' keys
Once again...many thanks...however when I try to implement them, the only two which work are VK_SPACE and VK_ESCAPE...here's a portion of my code so you may see my application for this.
sx *= 1.0/2.0;
sy *= 1.0/2.0;
<end of Code Fragment>
10-07-2000, 01:01 PM
Strange, I have no problem detecting the right key by comparing the virtual keycode to VK_RIGHT. I notice you are using glut. I have never used glut, so I'm guessing that glut is not returning virtual key codes, but rather ASCII or Unicode. Or perhaps it is a virtual key code, but somehow the arrow keys are being filtered out. Someone that is more familiar with glut should be able to say more about it.
Wolfman8k: I can't really tell which keys you say you are having trouble with. Maybe just say which keys without adding any punctuation, and just seperate them with spaces. Then I should be able to clearly see which keys you are talking about.
[This message has been edited by DFrey (edited 10-07-2000).]
you need to use glutSpecialKey func to get arrow keys esc etc.....
look it up here (glutSpecialFunc)
it also has codes for these keys
10-07-2000, 06:15 PM
Here are all the valid Windows virtual key-codes: http://msdn.microsoft.com/library/psdk/winui/vkeys_529f.htm
Thanks for the heads up on the 'K' thing. I made my life MUCH easier (I was looking up hex codes and testing aginst them). I was planning on implementing a header file with all the VK_A, VK_B, ... defined but I really didn't want to do that. Thank you again.
My post assumed, which was obviously wrong, that you was using the Win32 API for keyboard handling. In GLUT, keys are case sensitive, i.e. 's' does not equal 'S'. It depens on if caps lock or shift is pressed. In Win32 API, it's the physical key on the keybaord that is returned, not the virtual keycode generated by the operating system. And the arrowkeys got a different kind of keycode, think its two codes after each other, and therefore you can't just 'case VK_LEFT:' them as any other key.
You can use GetAsyncKeyState(keycode) instead, which returns true if the key is pressed. keycode is the physical key you want to detect, like VK_LEFT, VK_UP and so on. This only works on Win32 though.
10-08-2000, 10:12 AM
I followed the link to ms page mentioned above but I couldnt find any hexs for special characters like
"Å", "Ä", "Ö"
Has someone any ideas how to print these letters.
Thanks again to all of you... http://www.opengl.org/discussion_boards/ubb/smile.gif However I'm starting to think I'm having setup related issues since none of the WIN32 API codes except for VK_SPACE, VK_ESCAPE work and the GLUT_KEY_<key> does not want to work either. Is it possible for keyboard hardware to differ from one another?
But thanks for everything...these links are very useful to me in my programming endevours! http://www.opengl.org/discussion_boards/ubb/smile.gif
10-09-2000, 08:54 AM
Have you tried using Direct Input? It is really easy to implement, and fast.
10-09-2000, 09:25 AM
Why is directinput better than using windows messages? Can it detect more keypresses?
10-09-2000, 09:54 AM
If you use GetAsyncKeyState, you have to call it once for each key you need to check. With DirectInput, you can configure a keystate buffer. Then with just a single function call, the buffer is filled with the states of all keys. It is then just a simple test to see if any given key is up or down. It does not necessarily detect more keys being pressed at any given moment, as that is generally, a hardware limitation.
[This message has been edited by DFrey (edited 10-09-2000).]
No..I haven't tried that because I am not familiar with Direct Input. http://www.opengl.org/discussion_boards/ubb/redface.gif Could you guys please help me to understand this? Thanks... http://www.opengl.org/discussion_boards/ubb/smile.gif
10-09-2000, 11:31 PM
I agree with Wolfman!
A programmer starting with visual tools is often scared http://www.opengl.org/discussion_boards/ubb/eek.gif about window messages, but it's really really easy to use.
You simply have to catch a pair of wmsg, then you can control all your keyboard.
Sorry I can't give you the code... I haven't it here now.
Thanks Everyone...Your info has helped but I think this a matter of just sitting down for a day or two at my computer and playing around with the glut key catch stuff! http://www.opengl.org/discussion_boards/ubb/smile.gif Thanks again for everything!
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.