|
|
Thread Tools | Display Modes |
|
27-03-2011, 11:29 AM | #1 | ||
Join Date: Mar 2011
Location: ,
Posts: 13
|
Well, I think that going into SDL or any other external library just for this keyboard mapping functionality would be a kind of overkill.
IMHO it isn't possible to distinguish the RETURN (main keyboard) and ENTER (numpad) keys with GetAsyncKeyState(), precisely because both are mapped to the VK_RETURN virtual key. Same thing with other "duplicated" keys (such as +,-,*, etc.) IIRC. I suggest that you handle the WM_KEYDOWN event message through WinAPI. With this approach you'll get both the virtual key code (stored in wParam), which is the same as what you're getting already through calling GetAsyncKeyState(), and the so called "keydata" (stored in lParam). The 24th bit of the keydata parameter enables you to distinguish between the two ENTER keys (value 0 for RETURN, 1 for numpad ENTER). More info: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx If you intend to use this approach I think you'd be better of with axing the GetAsyncKeyState() calls and just listen for the WM_KEYDOWN events. I trust that you already know how to handle Windows messages inside a .NET application Last edited by Kanalia; 27-03-2011 at 11:33 AM. |
||
|
|
28-03-2011, 08:48 PM | #2 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
Thank you, that helped.
It seems I'm going to have to keep GetAsyncKeyState for one special case, namely the right ALT button. It returns the Left CTRL scancode when pressed, and I can only determine it's that button by checking GetAsyncKeyState. |
||
|
|
30-03-2011, 07:21 PM | #3 | ||
Join Date: Mar 2006
Location: ,
Posts: 4,613
|
Just for the record, today I remembered this thread and I thought that XNA (MS's .NET library for games programming) would have better types for input than Windows Forms. (Too bad Windows Forms and both WinAPI functions decide not to tell some equivalent keys apart, otherwise they could do the job.) I haven't tried XNA yet but here are some links on the topic, in case you want to explore:
http://msdn.microsoft.com/en-us/library/bb203899.aspx http://msdn.microsoft.com/en-us/library/bb203902.aspx http://msdn.microsoft.com/en-us/libr...ork.input.aspx Also it occurred to me that keyboard input may not be so simple as I was thinking initially, in a multi-tasking OS like Windows. Applications don't get input directly, it's the OS that decides to send it in a message to the one application that has focus. Also searching the MSDN forums I found a lot of threads about installing global hooks with the WinAPI to monitor input, but I wonder when such a crude bypass is recommended or actually used.
__________________
Life starts every day anew. Prospects not so good... Last edited by Japo; 30-03-2011 at 07:26 PM. |
||
|
|
01-04-2011, 06:13 PM | #4 | ||
Join Date: Mar 2011
Location: ,
Posts: 13
|
Quote:
As to the "special case", you don't need to keep GetAsyncKeyState just for that. The left and right ALT keys have their own keycodes defined, known respectively as VK_LMENU and VK_RMENU. Have you tried those? Also, IIRC, the RALT = LCTRL problem occurs usually when a non-US (or maybe non-English?) keyboard layout is set in the OS. Just for kicks, try out how your program works with US keyboard layout set (instead of Polish, which I presume is the case with you ). Also, if the above doesn't work, using the same way you already listen for WM_KEYDOWN messages, you could just add the special case for the WM_SYSKEYUP message. Details are available here: http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx It's easy to understand so I won't explain. Japo: Ah yes, it's not that easy. WinAPI is a pretty complicated API and there's usually more ways than one (or even two) to accomplish something, even if it seems to be something trivial Quote:
Utilizing XNA for a purely desktop windowed app makes about the same sense as using SDL in this case. Last edited by Kanalia; 01-04-2011 at 06:21 PM. |
||
|
|
02-04-2011, 12:11 PM | #5 | ||
Join Date: Oct 2004
Location: Opole, Poland
Posts: 14,276
|
Yes, the issue with the right Alt was a result of the non-US layout. But then, I do have to take all the possibilities into account including that the user will be running a layout like that. :/
|
||
|
|
03-04-2011, 12:28 AM | #6 | ||
Join Date: Mar 2011
Location: ,
Posts: 13
|
I never said that you shouldn't
|
||
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
regular | sgtboat | Blah, blah, blah... | 4 | 26-11-2008 03:30 AM |
When will regular updates start? | Doink | Blah, blah, blah... | 6 | 13-12-2007 10:00 AM |
How To Make Html/php Forms Read New Lines? | Danny252 | Programming | 2 | 05-01-2007 08:20 PM |
Enter Thevoid's Gallery | TheVoid | Music, Art, Movies | 672 | 26-06-2006 03:10 PM |
Regular Expressions | Kon-Tiki | Programming | 23 | 26-01-2006 09:58 PM |
|
|
||
  |