Click here to Skip to main content
13,201,940 members (75,205 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 19 Jul 2010

keyToggleChar – A tool to enter UTF-8 national chars via keyboard

, 19 Jul 2010
Rate this:
Please Sign up or sign in to vote.
A tool to enter UTF-8 national chars via keyboard

As you may know, my keyToggle app is able to use the number keys on a Windows mobile device as function keys. Here is another one that enables you to enter special national chars, like Å, Ä Æ etc. directly via the keyboard. You must specify 10 keys and their UTF-8 replacements. Configuration is done via the registry:

3.0        added code for read/write reg for CharTable and KeyTable


 KeyTable     holds a list of 10 keys which will be 'remapped'
 CharTable    holds  list of UniChar codes to use as replacement
 LEDid        defines the ID of the LED to use for showing sticky state
 autoFallback defines, if the sticky state is reset after a mapped key is pressed.
              Use 0, if you dont want the sticky state to fallback after keypress
 TimeOut      defines a timout after which sticky state will be reset

To get the UTF-8 word entries for Unicode chars, see for example:

The default mapping used here is defined as follows and maps the keys 0-9 to:

0x00c6, 0x00e6, 0x00d8, 0x00f8, 0x00C5, 0x00e5, 0x00c2, 0x00e2, 0x00c4, 0x00e4
 AE        ae     O/       o/      A°      a°      A^      a^      Ä       ä

The main problem I had was finding a function to get the window handle of the current input active window. Finally I found GetForegroundKeyboardTarget() (after some days of searching).

void sendKey(UINT vKey){
 TCHAR* lpText;
 lpText = new TCHAR[MAX_PATH];
 TCHAR strClass[MAX_PATH];
 int iRes;
 // hWndActive = GetFocusEx(); // a trick that does not deliver the focusses window
 hWndActive = GetForegroundKeyboardTarget();
 GetWindowText(hWndActive, lpText, MAX_PATH-1);
 iRes = GetClassName(hWndActive, strClass, MAX_PATH);
 DEBUGMSG(1, (L"### GetFocusEx() window, handle=0x%x, 
	text='%s', class='%s'\n", hWndActive, lpText, strClass));
 if(hWndActive == NULL)
 return; //no window found
 WPARAM wParam = getCharForKey(vKey); // charTable[vKey-0x30];// 0x00c6; //AE
 LPARAM lParam = 1; //flags: repeat=1
 wm_keydown, wParam=0, lParam=1
 wm_char, wParam=char code, lParam=1
 wm_keyup, wParam=0, lParam=c0000001;
 LRESULT lRes=0;
 lRes = SendMessage(hWndActive, WM_KEYDOWN, 0, 1);
 DEBUGMSG(1, (L"SendMessage1 for 'WM_KEYDOWN' returned 0x%0x\n", lRes));
 lRes = SendMessage(hWndActive, WM_CHAR, wParam, 1);
 DEBUGMSG(1, (L"SendMessage2 for '0x%04x' returned 0x%0x\n", wParam, lRes));
 lRes = SendMessage(hWndActive, WM_KEYUP, 0, 0xc0000001);
 DEBUGMSG(1, (L"SendMessage3 for 'WM_KEYUP' returned 0x%0x\n", lRes));

I left my different finding in code (commented out), so you can see what functions I have tried.

<!-- Social Bookmarks BEGIN -->

<!-- Social Bookmarks END -->


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171020.1 | Last Updated 19 Jul 2010
Article Copyright 2010 by hjgode
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid