Solved

OnKeyDown with "virtual key codes". How?

Posted on 2001-06-08
6
508 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual c++ and text files 7 69
Excel/Word Add-in in what language? 5 119
AVI wait icons for CAnimateCtrl in Visual Studio 2008 MFC 1 141
I could not build boost code, 10 89
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

832 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