there is a problem, if I store only the state of the keys how can I know the difference from WM_CHAR and WM_KEYDOWN messages? I mean, for example let's say that the user press the W key: it could be the action to move the player but also the action to write that letter in the chat...Sigh. I knew I was talking too early. You have not understood what's the difference between a character and a keypress.
This is NOT implementation detail.
Sigh. It is just so sad that in 2011 people just go around with shaders and still don't understand the most basic thing of keyboard processing.
So... take notice key buttons != text generated. Text != glyph. Go to your keyboard settings and mess a bit with it. If you don't want to see, http://en.wikipedia....eyboard_layouts.
You don't mix the two together. And by the way, components typically consuming key presses are rarely involved in character processing anyway.
October 2003:
Q: I still need a good method of getting keyboard input. Does anyone have any ideas that don''t involve testing for individual keys? I''m sure there''s some way I could do this using the WM_KEYDOWN scenario
A: WM_CHAR is the way I get text input from windows. ... I wouldn''t use the WM_CHAR for navigating a GL scene though but you can use WM_KEY messages [for this]...
March 2011:
Q: What can I do to make DirectInput translate the scancodes it receives to my current keyboard layout? ... DI only registers an 'A' keypress when I press 'Q'.
A: This is correct behavior, because AZERTY(A) is QWERTY(Q). Just writing "B" on a button does not make it generate char('b'). DirectInput (as well as WM_KEYDOWN) works on "scan codes" or "virtual key codes" which are roughly "the position of the button on the physical keyboard".
It seems like you have not correctly assimilated the [color="#8b0000"]important distinctions between
- The physical button being pressed on the keyboard ( suppose it's QWERTY(Y) )
- The sticker applied to the button pressed ('Y' on QWERTY)
- The character generated - 'y' or 'Y' on QWERTY, 'f' or 'F' on my layout - depending on window manager preferences.
- The glyph associated to the character in the given context (can be pretty much everything according to TrueType management)
- The scan code uniquely associated to the physical button pressed.
What you're doing with DI and WM_KEYDOWN is to work on (5). Which is the correct thing to do for "actions". Keyboard layout should really be considered only for text input.
July 2011
Q: Also, is there any input on which is better for mouse and keyboard input (not critical on speed just dependable) win32 or direct input. b/c direct input is a hunk of poo.
A: Yes, it is. Do not use DirectInput ... for character input, WM_CHAR works just fine. It has several advantages compared to DIY-input management such as 1) always correctly adapted to active locale and 2) behavior coherent with user settings (key repetitions per second etc).
For keyboard buttons, most of the time WM_KEYUP and WM_KEYDOWN work just fine... sometimes they get stuck when switching focus and such but I don't think that's a problem in general....[/quote]
I could go on forever dude. So I look forward to declare a day I will have taken this crusade for a decade. I want to thank all the people who actually also fight this apparently hopeless battle and all the people properly using the search button.