Solved

OnKeyDown with "virtual key codes". How?

Posted on 2001-06-08
6
513 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

691 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