Customize Android VNC Viewer Keys

android-vnc-viewer is the open source VNC viewer for Android platform. To be able to compile the codes without using Eclipse, do not use the codes from svn trunk. The reason is some of the auto-generated files using Eclipse plugin are missing in the svn trunk.

I use the codes from /svn/branches/antlersoft , retrieve using the command:

svn checkout http://android-vnc-viewer.googlecode.com/svn/branches/antlersoft android-vnc-viewer-antlersoft

I apply 2 patches that are attached in defect 238: Support additional keys, fix modifier handling and defect 239: Patch: Cursor key support for "Touch Mouse Pan and Zoom" mode.

The first patch, patch-android-vnc-viewer-extra-keys.diff maps a number of special keys and passes them to the VNC server correctly. These include the Tab, Ctrl, Alt, Page up, Page down, the function keys and some others.

The patch modifies the file androidVNC/src/android/androidVNC/VncCanvas.java . I added some more keys to pass to the VNC server. This includes mapping the Search key to the Escape key, and passing the Meta keys as well. We can get the X11 keysym codes from keysymdef.h. For eg., the X11 keysym value for the Escape key is 0xff1b.

 1 	public boolean processLocalKeyEvent(int keyCode, KeyEvent evt) {
2 ...
3 switch(keyCode) {
4 case KeyEvent.KEYCODE_BACK : key = 0xff1b; break;
5 ...
6 case KeyEvent.KEYCODE_SEARCH: key = 0xff1b; break; // escape key
7 ...
8 case 117 /* KEYCODE_META_LEFT */: key = 0xffe7; break;
9 case 118 /* KEYCODE_META_RIGHT */: key = 0xffe8; break;
10 ...
11 case 143 /* KEYCODE_NUM_LOCK */: key = 0xff7f; break;
12 default:
13 // Modifier handling is a bit tricky. Alt and Ctrl should be passed
14 // through to the VNC server so that they get handled there, but strip
15 // them from the character before retrieving the Unicode char from it.
16 // Don't clear Shift, we still want uppercase characters.
17 int vncEventMask = ( 0x7000 /* KeyEvent.META_CTRL_MASK */
18 | 0x0032 /* KeyEvent.META_ALT_MASK */
19 | 0x00070000 // META_META_MASK
20 );
21 ...
22

The second patch, patch-android-vnc-viewer-mode-switch.diff allows the VNC "Touch Mouse Pan and Zoom" mode to be able to use the DPad (Left/Right/Up/Down) keys as Left/Right/Up/Down keys. Without this patch, the DPad keys will actually move the mouse position. The patch uses the Tab key to switch to cursor mode (used as Left/Right/Up/Down keys), and uses DPad center to switch back to the default mouse mode.

The patch modifies the file /androidVNC/src/android/androidVNC/VncCanvasActivity.java . I made a little modification to this patch. I made the cursor mode as the default, since this is more useful. Instead of using 2 different keys to switch between cursor and mouse, I modify it to use a single key.


Documentation for user can be found at the android-vnc-viewer wiki.

If you do not need any customization, the VNC app can be installed from Google Play android-vnc-viewer app.


Refer to Android terminal-ide and Bluetooth Keyboard for why I map the Search key to the Escape key.

Comments

blog comments powered by Disqus