DX Keyboard Input

Started by
4 comments, last by Jemburula 17 years, 11 months ago
Hello, I've been playing around with the VK_* keystates to recieve text from the keyboard and display it in my DX application. However it's a bit annoying how everything is in capitals because it doesn't quite follow the ASCII key layout so I was wondering if there was something else I could use to get what keys have been pressed etc? Thank you! Jemburula
What we do in life... Echoes in eternity
Advertisement
WM_CHAR includes capitalization. Microsoft recommends that you use window messages for keyboard input for this reason.

The other alternative would be to check caps lock and shift to see if the letter should be in capitals or not.
As evil steve says, using the WM_CHAR event is the prefered way of handling this. If you ARE stuck with a DI based system (for legacy/political reasons), here's how to convert from DIK to wchar.


int Keyboard::Scan2ASCII(DWORD scancode, unsigned short* result){   static HKL layout=GetKeyboardLayout(0);   static unsigned char State[256];   if (GetKeyboardState(State)==FALSE)      return 0;   UINT vk=MapVirtualKeyEx(scancode,1,layout);   return ToAsciiEx(vk,scancode,State,result,0,layout);}


Good luck,

Allan
------------------------------ BOOMZAPTry our latest game, Jewels of Cleopatra
Hmmm thanks for the replies guys, not quite sure how to get it to work though so I'll post some of my code to show you what I am doing:

case WM_KEYDOWN:switch(wParam){case VK_ESCAPE:  PostQuitMessage(0);  break;case VK_OEM_3:  D3D->ConsoleToggle();  break;case VK_RETURN:  D3D->ConsoleReturn();  break;default:  break;};if(wParam == 32 || wParam >= 48 && wParam <= 122){  D3D->ConsoleInput((char)wParam);};break;

What I also need to be able to use the punctuation keys too, the simple conversion to (char) makes them turn into other symbols like if I press '.' it translate that to '3/4' sign. Sorry I'm pretty newb at this [smile] So do I have to check if Shift is pressed or does it send me the character code for the upper case letter/lower case letter? Thanks very much for your help. Awesomely lost without these forums lol

-Jemburula
What we do in life... Echoes in eternity
Programming Windows by Charles Petzold. -- 5th ed

I recommend this book for win32 api programming which you do. Has a ton of insane good information.

I could tell you alot of how to do this, but I would be writing too much of this book.

Get the book, you won't regret. Has all you need about this feature. ++ alot more.

But it is the WM_CHAR message you want to use to capture letters, and WM_KEYDOWN or UP, WM_SYSKEYDOWN or UP to look for key changes.
Hmm ok thanks for the reply, I'm going to fiddle around with WM_SYSKEYDOWN I suppose, ah well... it'll be a good thing to write as my first pitfall and solution for the journal we are supposed to keep. Thanks for the replies fellas, if you've got anymore input then feel free... there has got to be a better way to do this.
What we do in life... Echoes in eternity

This topic is closed to new replies.

Advertisement