Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Converting from KeyMap to UniChar

Converting from KeyMap to UniChar
Thread Tools
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Jul 28, 2005, 10:09 PM
 
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.

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:23 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2