Link to home
Start Free TrialLog in
Avatar of TropicalFish
TropicalFish

asked on

OnKeyDown with "virtual key codes". How?

I'm working in Borland C++ Builder 4 under win98.

I'm using the OnKeyDown event as input on a form. I want to determine which key was pressed, which works good in most cases. But the keys on the numeric keypad are reported all wrong, '1' gets value 97, '2' gets value 98 etc. I've heard something about "virtual key codes", what is it about, and how do I use it?

The OnKeyPress event handles the numeric keypad correctly, but can't handle the arrowkeys etc. so I don't want to use OnKeyPress.

Thanks for help
Avatar of scooter1
scooter1

Try VK_LEFT,VK_RIGHT, VK_UP, VK_DOWN for arrow keys, or try VK_NUMPAD4,VK_NUMPAD2 for numbers 4 and 2 on keypad.
Avatar of TropicalFish

ASKER

I need to register the ASCII character for the key pressed, like OnKeyPress does. if I convert the value I get like this: char(Key), then the numpad '1' becomes 'a'. I need to show the correct ASCII character for all keys that have one (all keys that OnKeyPress respond to) which includes the numpad +, -, * and /. The determination of what key was pressed works fine for all keys with OnKeyDown, it's the character that's returned that's not always right.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, I guess... even if it is very ugly.
Why do you insult me with a C?  I was trying to be helpful, so I post a comment providing a possible solution.   Now I have a C on my history.

In the future, I will know not to provide help to you.  Thanks for nothing.

-- Dan
I'm sorry if I offended you, I didn't realize that "average" was thought of as a really horrible grade. I thought it meant average as in not bad, but not great either. I do appreciate your help.