By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,304 Members | 2,042 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,304 IT Pros & Developers. It's quick & easy.

Correct Handling of Keypresses for a Control

P: 20
Hi. There are so many help offerings out there for the detection of keypresses. I would like to know what the "correct way" is to intercept a keypress for a control.

I have overidden the ProcessKeyPreview() method on a PropertGrid and I'm trying to intercept the arrows keys. Whats bugging me is that the wParam value is returning 0x25 (37) for an arrow keypress - this is the same as the ASCII % (percent) symbol.

Worse still, I also want to determine which keys are numeric, which keys are letters and which keys are printable characters in general. The % symbol is a printable character but the arrow key is not..

The other thing I feel really uncomfortable about is having to declare constants for Windows messages types such as WM_KEYDOWN, WM_CHAR etc. I would have thought that since C# is supposed to be a "nicer" language than C/C++, I shouldn't have to go browsing through winuser.h - something which I would expect to be Windows platform specific!

So.. Rather than comparing literal values for the arrow keys (which is what I've seen people offering as help to others!) .. is there a better way this can be done? In otherwords, can the wParam value of WM_KEYDOWN/WM_CHAR messages be nicely converted into a Keys.???? enumerated value?

Is anyone able to offer the world some nice code that does this?

Thanks
Sparky.
Jul 24 '07 #1
Share this Question
Share on Google+
1 Reply


P: 20
Of course, stupid me - there isn't actually a % key anyway is there??? DOH!!! I guess the 0x25 value can be used for the left arrow key after all..
Jul 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.