Okay, to the best of my knowledge, I'm doing everything correctly. I need to figure out what key a user has pressed without blocking or waiting for an event. I'm using GetKeys() to get a KeyMap of what key has been pressed, and then I step through that with a for loop to get the virtual key code, like so:
Code:
for(unsigned int x=0; x<128; x++)
{
if ( m_UsedKeys[x/32] & (1L << x%32) )
{
do stuff...
So, I have x+1 as the virtual key code, and I need to take that and convert it to a UniChar. Of course, the correct way to do that is with UCKeyTranslate (since the app won't be just in English). That, I'm doing about like this:
Code:
const void * myKeyLayout;
UInt32 deadKeyState;
SInt16 currentKeyScript;
SInt16 lastKeyLayoutID;
UniChar unicodeInputString[kMaxUnicodeInputStringLength];
OSStatus status;
KeyboardLayoutRef layoutref;
KLGetCurrentKeyboardLayout(&layoutref);
KLGetKeyboardLayoutProperty(layoutref,kKLuchrData,&myKeyLayout);
deadKeyState = 0;
UInt32 keyboardType;
UInt32 modifierKeyState;
UInt16 virtualKeyCode;
UInt16 keyAction;
UniCharCount actualStringLength;
virtualKeyCode = x+1;
keyAction = kUCKeyActionDown;
modifierKeyState = GetCurrentEventKeyModifiers();
keyboardType = LMGetKbdType();
status = UCKeyTranslate(static_cast<const UCKeyboardLayout *>(myKeyLayout),
virtualKeyCode,
keyAction,
modifierKeyState,
keyboardType,
kUCKeyTranslateNoDeadKeysBit,
&deadKeyState,
kMaxUnicodeInputStringLength,
&actualStringLength,
unicodeInputString);
At this point, I have a single UniChar in unicodeInputString. However, when I press the 'a' key, it translates to '9'. The 's' key translates to '8'. This is completely different from the 27 and 28 (or whatever it is) that I get from the KeyMap.
Any ideas?
Better yet, does anyone know of an easier way to do this with wxWidgets 2.6? btw, it looks like I have the translation from UniChar[] to wxString running correctly.
Thanks for any input you have to offer.