Skip to content

Commit

Permalink
Now using left Alt KeyEvent metaState for remote state as well.
Browse files Browse the repository at this point in the history
Previously, left Alt was ignored even for non-default-hardware keyboards.
This is now fixed, and left Alt is honored on soft keyboards like
Hacker's Keyboard.
  • Loading branch information
iiordanov committed Dec 21, 2013
1 parent 3ca920c commit 4468a4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,20 @@ public void sendUnicode (char unicodeChar, int additionalMetaState) {
protected int convertEventMetaState (KeyEvent event) {
int metaState = 0;
int eventMetaState = event.getMetaState();
int altMask = KeyEvent.META_ALT_RIGHT_ON;
// Detect whether this event is coming from a default hardware keyboard.
// We have to leave KeyEvent.KEYCODE_ALT_LEFT for symbol input on a default hardware keyboard.
boolean defaultHardwareKbd = (event.getDeviceId() == 0);
if (!defaultHardwareKbd) {
altMask = KeyEvent.META_ALT_MASK;
}

// Add shift, ctrl, alt, and super to metaState if necessary.
// TODO: We leave KeyEvent.KEYCODE_ALT_LEFT for symbol input on hardware keyboards for now.
if ((eventMetaState & 0x000000c1 /*KeyEvent.META_SHIFT_MASK*/) != 0)
metaState |= SHIFT_MASK;
if ((eventMetaState & 0x00007000 /*KeyEvent.META_CTRL_MASK*/) != 0 )
if ((eventMetaState & 0x00007000 /*KeyEvent.META_CTRL_MASK*/) != 0)
metaState |= CTRL_MASK;
if ((eventMetaState & KeyEvent.META_ALT_RIGHT_ON) !=0)
if ((eventMetaState & altMask) !=0)
metaState |= ALT_MASK;
if ((eventMetaState & 0x00070000 /*KeyEvent.META_META_MASK*/) != 0)
metaState |= SUPER_MASK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,20 @@ public boolean processLocalKeyEvent(int keyCode, KeyEvent evt, int additionalMet
unicode = true;
}
break;
default:
default:
// Modifier handling is a bit tricky. Alt, Ctrl, and Super should be passed
// through to the VNC server so that they get handled there, but strip
// them from the character before retrieving the Unicode char from it.
// Don't clear Shift, we still want uppercase characters.
int metaMask = ( 0x00007000 | 0x00070000); // KeyEvent.META_CTRL_MASK | KeyEvent.META_META_MASK
int metaMask = ( 0x00007000 | 0x00070000 ); // KeyEvent.META_CTRL_MASK | KeyEvent.META_META_MASK
// We still want alt-key combinations to give us symbols, so we only strip out KeyEvent.META_ALT_MASK
// if we've decided to send out ALT as a separate key modifier over.
if ((metaState & ALT_MASK) != 0)
if ((metaState & ALT_MASK) != 0) {
metaMask |= 0x00000032;
}
KeyEvent copy = new KeyEvent(evt.getDownTime(), evt.getEventTime(), evt.getAction(),
evt.getKeyCode(), evt.getRepeatCount(),
evt.getMetaState() & ~metaMask, evt.getDeviceId(), evt.getScanCode());
evt.getKeyCode(), evt.getRepeatCount(), evt.getMetaState() & ~metaMask,
evt.getDeviceId(), evt.getScanCode());
key = copy.getUnicodeChar();
keysym = UnicodeToKeysym.translate(key);
break;
Expand Down Expand Up @@ -180,7 +181,7 @@ public boolean processLocalKeyEvent(int keyCode, KeyEvent evt, int additionalMet

metaState = metaState|onScreenMetaState|hardwareMetaState;
if (numchars == 1) {
//android.util.Log.e(TAG,"Sending key. Down: " + down + ", key: " + key + ". keysym:" + keysym + ", metaState: " + metaState);
//android.util.Log.e(TAG, "Sending key. Down: " + down + ", key: " + key + ". keysym:" + keysym + ", metaState: " + metaState);
rfb.writeKeyEvent(keysym, metaState, down);
// If this is a unicode key, the up event will never come, so we artificially insert it.
if (unicode)
Expand All @@ -190,7 +191,7 @@ public boolean processLocalKeyEvent(int keyCode, KeyEvent evt, int additionalMet
for (int i = 0; i < numchars; i++) {
key = evt.getCharacters().charAt(i);
keysym = UnicodeToKeysym.translate(key);
//android.util.Log.e(TAG,"Sending multiple keys. Key: " + key + " keysym: " + keysym + ", metaState: " + metaState);
//android.util.Log.e(TAG, "Sending multiple keys. Key: " + key + " keysym: " + keysym + ", metaState: " + metaState);
rfb.writeKeyEvent(keysym, metaState, true);
rfb.writeKeyEvent(keysym, metaState, false);
}
Expand Down

0 comments on commit 4468a4b

Please sign in to comment.