Solved

OnKeyDown with "virtual key codes". How?

Posted on 2001-06-08
6
506 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:TropicalFish
  • 3
  • 2
6 Comments
 

Expert Comment

by:scooter1
ID: 6170066
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.
0
 

Author Comment

by:TropicalFish
ID: 6170547
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.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 75 total points
ID: 6175091
Try:
if (key==VK_NUMPAD4) char='4';
(etc)

-- Dan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:TropicalFish
ID: 6178066
Yeah, I guess... even if it is very ugly.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6178406
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
0
 

Author Comment

by:TropicalFish
ID: 6183384
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now