Original Post
Okay, so what I get from a Direct Input device (keyboard) is scan codes. I need to translate this into more sensible keystrokes. For instance, i'm a bit concerned with keyboard layouts. I know of a couple popular functions like MapVirtualKeyEx and ToAsciiEx. It would be fine by me to constrain the input to this (e.g. not considering Japanees). The thing is that the acutal returned language by GetKeyboardLayout() on main thread is still 'en' while i use a swedish keyboard layout. But this seem to have some other unforseen impact, as 'W' ends up as a upwards arrow in the console. And don't even get me started on characters such as åäö, or for that matter CAPS LOCK or Shift combinations... it' seem to make no difference... This is the code I'm using:
S_UINT read = 10;
HRESULT hr = m_dx8Keyboard->GetDeviceData( sizeof( DIDEVICEOBJECTDATA ), m_dData, (LPDWORD)&read, 0 );
m_dx8Keyboard->GetDeviceState( 0x100, m_keyboardState )
for( S_UINT i = 0; i < read; i++ )
{
WORD c;
S_UINT sc = m_dData.dwOfs; // Scan code
S_UINT vkey = MapVirtualKeyEx( sc, 1, m_keyboardLayout );
if( ToAsciiEx( vkey, sc, m_keyboardState, &c, 0, m_keyboardLayout ) )
printf( "KEY %3u %c\n", sc, char(c) );
}
This is just a fragment, but I hope it shows well enough of what I'm currently doing. e.g. that I'm using the state from the direct input device and what methods i'm calling to get the actual output. I don't mind writing a bit of code, but what I want is a way of mapping these direct input scan codes to some sensible text output, or keystrokes. probably by putting this into my own custom format to represent actions i can trigger on certain combinations. But i wannt to use as much of the WINAPI as possible to accomplish this so that most of the work will be done by the API as long as the correct input locale is provided. But this is obivously not working and I'm not sure why...
m_keyboardLayout = GetKeyboardLayout(); // Current thread
WORD lcid = (WORD)m_keyboardLayout; // low-word equals language identifier
CHAR langName[9];
GetLocaleInfo( lcid, LOCALE_SISO639LANGNAME, langName, 9 );
printf( "ISO639LANGNAME: %s\n", langName );
e.g. the above code should (according to me) print 'sv' since that's my keyboard layout, but it prints 'en'... I would be very greatful for any advice when using a Direct Input Keyboard.