How to emulate international hardware keyboard?

272 views
Skip to first unread message

Jörg Wille

unread,
Jan 13, 2015, 10:38:41 AM1/13/15
to hackers...@googlegroups.com
I am developing an Android Application to remotely control a PC/Mac with an emulated Mouse and Soft-Keyboard. Hackerskeyboard seems to be very well suited for this purpose, because it emulate the layout of a hardware keyboard.
But I have a problem of understanding how Hackerskeyboard and Android KeyEvents work in case of German Umlaute.

In my code I use dispatchKeyEvent to track Android KeyEvents.
When I hit a "regular" character button I can log following events:

KeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_L, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=1519045, downTime=1519045, deviceId=-1, displayId=0, source=0x101 }

KeyEvent: KeyEvent { action=ACTION_UP, keyCode=KEYCODE_L, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=1519045, downTime=1519045, deviceId=-1, displayId=0, source=0x101 }

I use the keyCode (here keyCode=KEYCODE_L to map with a HID-Keyboard scan code, which I send to the remote PC and all is fine. On english-layout soft-keyboard this mapping works for all keys. 


But when change Hackerskeyboard layout to German and I hit a Umlaut-Key I only get following event:

KeyEvent: KeyEvent { action=ACTION_MULTIPLE, keyCode=KEYCODE_UNKNOWN, scanCode=0, characters="ö", metaState=0, flags=0x0, repeatCount=0, eventTime=8654991, downTime=8654991, deviceId=-1, displayId=0, source=0x101 }


I guess this behavior of Android is similar to awt to javafx where they point out the difference between low-level "Key pressed" and "key released" events and higher-level "Key typed", which are generated when a Unicode character was sent to system input.


One way to solve this would be to create special layouts for my purpose. For example a German layout should look just like the regular Hackerskeyboard's German-5-row keyboard but should behave like a English-5-row keyboard, e.g. send the same KeyEvents like the regular English-5-row keyboard.

This way, when I hit on the button which shows the ö Umlaut it would send the KeyCode SEMICOLON and would turn out as an ö on the remote PC. This would perfectly emulate a (german) hardware-keyboard.


From my first look into "donottranslate-keymap.xml" this kind of configuration does not seem to be supported. It looks to me, that the character shown on the key-button is the same character which Hackerskeyboard passes to Android.

And Android seem to generate the Key-Up/Down-Events with either a valid KEYCODE or a different KeyEvent with KEYCODE_UNKNOWN. Am I right with my assumption?


Are there maybe better approaches to emulate international hardware keyboard with an Android software keyboard. I cannot do the mapping on remote PC since I want to be HID compliant, e.g. emulate a real USB-Keyboard.

Reply all
Reply to author
Forward
0 new messages