Index: remoting/android/java/src/org/chromium/chromoting/Desktop.java |
diff --git a/remoting/android/java/src/org/chromium/chromoting/Desktop.java b/remoting/android/java/src/org/chromium/chromoting/Desktop.java |
index 5e79e497d7a07ae2a3f713c110540be5a2b3a28e..3a1cf14704adc376f105ffb1b6787cfb78d85a19 100644 |
--- a/remoting/android/java/src/org/chromium/chromoting/Desktop.java |
+++ b/remoting/android/java/src/org/chromium/chromoting/Desktop.java |
@@ -228,10 +228,10 @@ public class Desktop extends AppCompatActivity implements View.OnSystemUiVisibil |
KeyEvent.KEYCODE_FORWARD_DEL, |
}; |
for (int key : keys) { |
- JniInterface.sendKeyEvent(key, true); |
+ JniInterface.sendKeyEvent(0, key, true); |
} |
for (int key : keys) { |
- JniInterface.sendKeyEvent(key, false); |
+ JniInterface.sendKeyEvent(0, key, false); |
} |
return true; |
} |
@@ -256,10 +256,21 @@ public class Desktop extends AppCompatActivity implements View.OnSystemUiVisibil |
return super.dispatchKeyEvent(event); |
} |
- // Send TextEvent in two cases: |
+ boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; |
+ |
+ // Physical keyboard must work as if it is connected to the remote host |
+ // and so events coming from physical keyboard never generate text |
+ // events. Also scan codes must be used instead of key code, so that |
+ // the keyboard layout selected on the client doesn't affect the key |
+ // codes sent to the host. |
+ if (event.getDeviceId() != KeyCharacterMap.VIRTUAL_KEYBOARD) { |
+ return JniInterface.sendKeyEvent(event.getScanCode(), 0, pressed); |
+ } |
+ |
+ // Events received from software keyboards generate TextEvent in two |
+ // cases: |
// 1. This is an ACTION_MULTIPLE event. |
- // 2. The event was generated by on-screen keyboard and Ctrl, Alt and |
- // Meta are not pressed. |
+ // 2. Ctrl, Alt and Meta are not pressed. |
// This ensures that on-screen keyboard always injects input that |
// correspond to what user sees on the screen, while physical keyboard |
// acts as if it is connected to the remote host. |
@@ -268,8 +279,6 @@ public class Desktop extends AppCompatActivity implements View.OnSystemUiVisibil |
return true; |
} |
- boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; |
- |
// For Enter getUnicodeChar() returns 10 (line feed), but we still |
// want to send it as KeyEvent. |
int unicode = keyCode != KeyEvent.KEYCODE_ENTER ? event.getUnicodeChar() : 0; |
@@ -277,8 +286,7 @@ public class Desktop extends AppCompatActivity implements View.OnSystemUiVisibil |
boolean no_modifiers = !event.isAltPressed() |
&& !event.isCtrlPressed() && !event.isMetaPressed(); |
- if (event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD |
- && pressed && unicode != 0 && no_modifiers) { |
+ if (pressed && unicode != 0 && no_modifiers) { |
mPressedTextKeys.add(keyCode); |
int[] codePoints = { unicode }; |
JniInterface.sendTextEvent(new String(codePoints, 0, 1)); |
@@ -291,29 +299,33 @@ public class Desktop extends AppCompatActivity implements View.OnSystemUiVisibil |
} |
switch (keyCode) { |
+ // KEYCODE_AT, KEYCODE_POUND, KEYCODE_STAR and KEYCODE_PLUS are |
+ // deprecated, but they still need to be here for older devices and |
+ // third-party keyboards that may still generate these events. See |
+ // https://source.android.com/devices/input/keyboard-devices.html#legacy-unsupported-keys |
case KeyEvent.KEYCODE_AT: |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_2, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_2, pressed); |
return true; |
case KeyEvent.KEYCODE_POUND: |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_3, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_3, pressed); |
return true; |
case KeyEvent.KEYCODE_STAR: |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_8, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_8, pressed); |
return true; |
case KeyEvent.KEYCODE_PLUS: |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
- JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
+ JniInterface.sendKeyEvent(0, KeyEvent.KEYCODE_EQUALS, pressed); |
return true; |
default: |
// We try to send all other key codes to the host directly. |
- return JniInterface.sendKeyEvent(keyCode, pressed); |
+ return JniInterface.sendKeyEvent(0, keyCode, pressed); |
} |
} |
} |