Solved

OnKeyDown with "virtual key codes". How?

Posted on 2001-06-08
6
505 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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

12 Experts available now in Live!

Get 1:1 Help Now