Skip to content

Commit

Permalink
game menu: use modifier for send keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim Mreisi committed Feb 15, 2023
1 parent ba0b94b commit 2772ab1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/src/main/java/com/limelight/GameMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,40 @@ private String getString(int id) {
return game.getResources().getString(id);
}

private static byte getModifier(short key) {
switch (key) {
case KeyboardTranslator.VK_LSHIFT:
return KeyboardPacket.MODIFIER_SHIFT;
case KeyboardTranslator.VK_LCONTROL:
return KeyboardPacket.MODIFIER_CTRL;
case KeyboardTranslator.VK_LWIN:
return KeyboardPacket.MODIFIER_META;

default:
return 0;
}
}

private void sendKeys(short[] keys) {
final byte[] modifier = {(byte) 0};

for (short key : keys) {
conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, (byte) 0);
conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, modifier[0]);

// Apply the modifier of the pressed key, e.g. CTRL first issues a CTRL event (without
// modifier) and then sends the following keys with the CTRL modifier applied
modifier[0] |= getModifier(key);
}

new Handler().postDelayed((() -> {

for (int pos = keys.length - 1; pos >= 0; pos--) {
short key = keys[pos];

conn.sendKeyboardInput(key, KeyboardPacket.KEY_UP, (byte) 0);
// Remove the keys modifier before releasing the key
modifier[0] &= ~getModifier(key);

conn.sendKeyboardInput(key, KeyboardPacket.KEY_UP, modifier[0]);
}
}), KEY_UP_DELAY);
}
Expand Down

0 comments on commit 2772ab1

Please sign in to comment.