[DX9] Textual input from keyboard state?

Started by
3 comments, last by MJP 14 years, 1 month ago
Hi everyone ! I'm currently working on a GUI for a game engine of mine and it just occurred to me that I don't really know how to extract textual data from the keyboard state array I maintain using GetDeviceState(). Well, I know I could check for "DIK"-macro matches using a big-ass switch, but surely there must be a smoother way? I would very much like to be able to recognize capital letter input (shift-modified) if possible since it is a textbox-like item for inserting character names and the likes. I thought I shouldn't provide any of my source code since it is pretty stupid so far but my idea was to check for keyboard input every time the GUI-component's Update() method is called and if any - add to it's private string both to display while typing and to pass on when the user is done. If anyone might be able to help me solve this I'd be very grateful :)
Advertisement
Why not just process the WM_CHAR or WM_UNICHAR window messages?
Quote:Original post by SiCrane
Why not just process the WM_CHAR or WM_UNICHAR window messages?


I guess my current Input class might be a bit too simple for this case. It could be extended to read input from there, but does that take into account when a character key is modified by shift?

Edit: As far to my knowledge I would have to check individually for the shift keydown and subtract 32 from the other pressed key, but this would only work in the event of an alphabetical key being pressed.

[Edited by - Vanderry on March 12, 2010 6:51:30 PM]
To conclude this thread I found the solution in an article here on GameDev. Wish I had found it before I started the thread but just for future reference, there it is x)
WM_CHAR/WM_UNICHAR will take things like the shift key + keyboard layout + language settings into account. It basically gives you the character that you would want to ultimately display in a text box.

This topic is closed to new replies.

Advertisement