Advertisement

Why won't VK_R work?

Started by July 02, 2000 02:22 PM
11 comments, last by Muzzafarath 24 years, 5 months ago
This Windows programming is driving me crazy :mad:! I''ve got a macro called KEYDOWN (take from Tricks of the Windows Game Programming Gurus), and I want to check whether or not the R key is down. if(KEYDOWN(VK_R)) { // R key is down } Looks alright doesn''t it? The problem is that the compiler says that VK_R doesn''t exist... But if I replace VK_R with VK_ESCAPE everything works. This works though: if(KEYDOWN(0x52))) { // R key is down } Where is VK_R defined? Do I have to define all of those VK constants myself? - Muzzafarath Mad House Software The Field Marshals
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
use this:

if(KEY_DOWN(''R''))
{
//r is down
}

make sure to always use capital letters, not lowercase.

i found a good site with a VERY complete list of key codes and their hex values:

http://a1computers.net/pcascii.htm
==============================
whats a signature?
htm[s]l[/s]
Advertisement
Ah yes of course, character constants... But why doesn''t VK_R work...? It should work.

- Muzzafarath

Mad House Software
The Field Marshals
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
It doesn''t work because there are no VK_ constants defined for letters (and maybe numbers too). You are supposed to just use the character constants.
The reason there are no VK_ constants for letters and such is that the keycode is the ascii value, so they figured why bother making constants.

-Zims
just create a console app, and cut and paste this, and you will have the character codes...
        #include <fstream.h>main (){ofstream outfile ("Filename.h", ios::out);outfile << "#ifndef _VK_CHAR_CODES_H_\n#define_VK_CHAR_CODES_H_\n";for (char i = 'A'; i <= 'Z'; i++)  outfile << "#define VK_" << i << "'" << i << "'\n";for (char i = '0'; i <= '9'; i++)  outfile << "#define VK_" << i << "'" << i << "'\n";outfile << "#endif // _VK_CHAR_CODES_H_";outfile.close ();return (0);}        


this should create for you a header file that contains all the VK_'char' codes you want to use, including the numbers. i just had nothing else to do at the moment, that's why i did this, and also cuz it's pretty fun... hehe... o well...
farmersckn

Sometimes even chickens need to eat... Don't bang your head against a wall just to enjoy the good feeling when you stop.

Edited by - farmersckn on July 2, 2000 11:43:17 PM
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Advertisement
quote: Original post by Zimans

The reason there are no VK_ constants for letters and such is that the keycode is the ascii value, so they figured why bother making constants.

-Zims


But then, why do MS list them in MSDN?

- Muzzafarath

Mad House Software
The Field Marshals
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
According to the Win32 Programming Bible, Simon 1996, VK_A thru VK_Z and VK_0 thru VK_9 *DO* exist. It may be a matter of including the correct .h file - or - possibly the macro doesn't resolve the identifier correctly. Try a traditional switch/case using VK_R...

...Wow, I just got upgraded to Fanatic!

Edited by - Bill Adams on July 3, 2000 8:33:21 AM
Muzzafarth(spelled correctly??) is right:WHY THE HELL DO THEY LIST VK_R IN THE HELP IF ONE CANNOT USE IT????
This one made me crazy too,some time ago.
Anyway gameprogrammerwiz´s solution works but I still wonder....

P.s.:Which version of VC++ do you use?Perhaps this problem doesn´t exist in VC++6.0 anymore:confused:
Greets,XBTC!
Hey,why doesn´t the :confused: smiley work here

This topic is closed to new replies.

Advertisement