mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-26 06:22:45 +00:00
Use a global set of modifier flags rather than per-device flags
Fixes #840
This commit is contained in:
parent
20ced841dd
commit
1d3e42f92e
@ -598,6 +598,10 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
public void onWindowFocusChanged(boolean hasFocus) {
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
super.onWindowFocusChanged(hasFocus);
|
super.onWindowFocusChanged(hasFocus);
|
||||||
|
|
||||||
|
// We can't guarantee the state of modifiers keys which may have
|
||||||
|
// lifted while focus was not on us. Clear the modifier state.
|
||||||
|
this.modifierFlags = 0;
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
// Capture is lost when focus is lost, so it must be requested again
|
// Capture is lost when focus is lost, so it must be requested again
|
||||||
// when focus is regained.
|
// when focus is regained.
|
||||||
@ -996,20 +1000,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte getModifierState(KeyEvent event) {
|
|
||||||
byte modifier = 0;
|
|
||||||
if (event.isShiftPressed()) {
|
|
||||||
modifier |= KeyboardPacket.MODIFIER_SHIFT;
|
|
||||||
}
|
|
||||||
if (event.isCtrlPressed()) {
|
|
||||||
modifier |= KeyboardPacket.MODIFIER_CTRL;
|
|
||||||
}
|
|
||||||
if (event.isAltPressed()) {
|
|
||||||
modifier |= KeyboardPacket.MODIFIER_ALT;
|
|
||||||
}
|
|
||||||
return modifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte getModifierState() {
|
private byte getModifierState() {
|
||||||
return (byte) modifierFlags;
|
return (byte) modifierFlags;
|
||||||
}
|
}
|
||||||
@ -1075,7 +1065,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte modifiers = getModifierState(event);
|
byte modifiers = getModifierState();
|
||||||
if (KeyboardTranslator.needsShift(event.getKeyCode())) {
|
if (KeyboardTranslator.needsShift(event.getKeyCode())) {
|
||||||
modifiers |= KeyboardPacket.MODIFIER_SHIFT;
|
modifiers |= KeyboardPacket.MODIFIER_SHIFT;
|
||||||
conn.sendKeyboardInput((short) 0x8010, KeyboardPacket.KEY_DOWN, modifiers);
|
conn.sendKeyboardInput((short) 0x8010, KeyboardPacket.KEY_DOWN, modifiers);
|
||||||
@ -1139,13 +1129,13 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte modifiers = getModifierState(event);
|
byte modifiers = getModifierState();
|
||||||
if (KeyboardTranslator.needsShift(event.getKeyCode())) {
|
if (KeyboardTranslator.needsShift(event.getKeyCode())) {
|
||||||
modifiers |= KeyboardPacket.MODIFIER_SHIFT;
|
modifiers |= KeyboardPacket.MODIFIER_SHIFT;
|
||||||
}
|
}
|
||||||
conn.sendKeyboardInput(translated, KeyboardPacket.KEY_UP, modifiers);
|
conn.sendKeyboardInput(translated, KeyboardPacket.KEY_UP, modifiers);
|
||||||
if (KeyboardTranslator.needsShift(event.getKeyCode())) {
|
if (KeyboardTranslator.needsShift(event.getKeyCode())) {
|
||||||
conn.sendKeyboardInput((short) 0x8010, KeyboardPacket.KEY_UP, getModifierState(event));
|
conn.sendKeyboardInput((short) 0x8010, KeyboardPacket.KEY_UP, getModifierState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user