Skip to content

Commit 29f1613

Browse files
author
Karim Mreisi
committed
game menu: use modifier for send keys
1 parent f60a5ac commit 29f1613

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

app/src/main/java/com/limelight/GameMenu.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,40 @@ private String getString(int id) {
4141
return game.getResources().getString(id);
4242
}
4343

44+
private static byte getModifier(short key) {
45+
switch (key) {
46+
case KeyboardTranslator.VK_LSHIFT:
47+
return KeyboardPacket.MODIFIER_SHIFT;
48+
case KeyboardTranslator.VK_LCONTROL:
49+
return KeyboardPacket.MODIFIER_CTRL;
50+
case KeyboardTranslator.VK_LWIN:
51+
return KeyboardPacket.MODIFIER_META;
52+
53+
default:
54+
return 0;
55+
}
56+
}
57+
4458
private void sendKeys(short[] keys) {
59+
final byte[] modifier = {(byte) 0};
60+
4561
for (short key : keys) {
46-
conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, (byte) 0);
62+
conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, modifier[0]);
63+
64+
// Apply the modifier of the pressed key, e.g. CTRL first issues a CTRL event (without
65+
// modifier) and then sends the following keys with the CTRL modifier applied
66+
modifier[0] |= getModifier(key);
4767
}
4868

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

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

54-
conn.sendKeyboardInput(key, KeyboardPacket.KEY_UP, (byte) 0);
74+
// Remove the keys modifier before releasing the key
75+
modifier[0] &= ~getModifier(key);
76+
77+
conn.sendKeyboardInput(key, KeyboardPacket.KEY_UP, modifier[0]);
5578
}
5679
}), KEY_UP_DELAY);
5780
}

0 commit comments

Comments
 (0)