From 0931adf5785a5d431e651489fdeb7560c5447604 Mon Sep 17 00:00:00 2001 From: Karim Mreisi Date: Sat, 21 Jan 2023 11:56:03 +0100 Subject: [PATCH] game menu: cleanup + fix steam overlay --- app/src/main/java/com/limelight/GameMenu.java | 52 +++++++++++-------- .../binding/input/KeyboardTranslator.java | 9 +++- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/limelight/GameMenu.java b/app/src/main/java/com/limelight/GameMenu.java index 544018446..c637d2756 100644 --- a/app/src/main/java/com/limelight/GameMenu.java +++ b/app/src/main/java/com/limelight/GameMenu.java @@ -1,18 +1,22 @@ package com.limelight; import android.app.AlertDialog; +import android.os.Handler; import android.widget.ArrayAdapter; +import com.limelight.binding.input.KeyboardTranslator; import com.limelight.nvstream.NvConnection; import com.limelight.nvstream.input.KeyboardPacket; /** * Provide options for ongoing Game Stream. - * + *

* Shown on back action in game activity. */ public class GameMenu { + private static final long KEY_UP_DELAY = 25; + private static class MenuOption { private final String label; private final Runnable runnable; @@ -37,14 +41,19 @@ private String getString(int id) { return game.getResources().getString(id); } - private void sendKeySequence(byte modifier, short[] keys) { - for (short key : keys) - conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, - (byte) (modifier | KeyboardPacket.KEY_DOWN)); + private void sendKeys(short[] keys) { + for (short key : keys) { + conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, (byte) 0); + } + + new Handler().postDelayed((() -> { - for (int pos = keys.length - 1; pos >= 0; pos--) - conn.sendKeyboardInput(keys[pos], KeyboardPacket.KEY_UP, - (byte) (modifier | KeyboardPacket.KEY_UP)); + for (int pos = keys.length - 1; pos >= 0; pos--) { + short key = keys[pos]; + + conn.sendKeyboardInput(key, KeyboardPacket.KEY_UP, (byte) 0); + } + }), KEY_UP_DELAY); } private void showMenuDialog(String title, MenuOption[] options) { @@ -77,21 +86,18 @@ private void showMenuDialog(String title, MenuOption[] options) { private void showSpecialKeysMenu() { showMenuDialog(getString(R.string.game_menu_send_keys), new MenuOption[]{ - new MenuOption(getString(R.string.game_menu_send_keys_esc), () -> sendKeySequence( - (byte) 0, new short[]{0x18})), - new MenuOption(getString(R.string.game_menu_send_keys_f11), () -> sendKeySequence( - (byte) 0, new short[]{0x7a})), - new MenuOption(getString(R.string.game_menu_send_keys_win), () -> sendKeySequence( - (byte) 0, new short[]{0x5B})), - new MenuOption(getString(R.string.game_menu_send_keys_win_d), () -> sendKeySequence( - (byte) 0, new short[]{0x5B, 0x44})), - new MenuOption(getString(R.string.game_menu_send_keys_win_g), () -> sendKeySequence( - (byte) 0, new short[]{0x5B, 0x47})), - /* - // TODO: Currently not working - new MenuDialogOption(getString(R.string.game_menu_send_keys_shift_tab), () -> sendKeySequence( - (byte) 0, new short[]{0xA0, 0x09})), - */ + new MenuOption(getString(R.string.game_menu_send_keys_esc), + () -> sendKeys(new short[]{KeyboardTranslator.VK_ESCAPE})), + new MenuOption(getString(R.string.game_menu_send_keys_f11), + () -> sendKeys(new short[]{KeyboardTranslator.VK_F11})), + new MenuOption(getString(R.string.game_menu_send_keys_win), + () -> sendKeys(new short[]{KeyboardTranslator.VK_LWIN})), + new MenuOption(getString(R.string.game_menu_send_keys_win_d), + () -> sendKeys(new short[]{KeyboardTranslator.VK_LWIN, KeyboardTranslator.VK_D})), + new MenuOption(getString(R.string.game_menu_send_keys_win_g), + () -> sendKeys(new short[]{KeyboardTranslator.VK_LWIN, KeyboardTranslator.VK_G})), + new MenuOption(getString(R.string.game_menu_send_keys_shift_tab), + () -> sendKeys(new short[]{KeyboardTranslator.VK_LSHIFT, KeyboardTranslator.VK_TAB})), new MenuOption(getString(R.string.game_menu_cancel), null), }); } diff --git a/app/src/main/java/com/limelight/binding/input/KeyboardTranslator.java b/app/src/main/java/com/limelight/binding/input/KeyboardTranslator.java index 8ccda4ddf..002bfaa0a 100644 --- a/app/src/main/java/com/limelight/binding/input/KeyboardTranslator.java +++ b/app/src/main/java/com/limelight/binding/input/KeyboardTranslator.java @@ -24,6 +24,8 @@ public class KeyboardTranslator implements InputManager.InputDeviceListener { public static final int VK_0 = 48; public static final int VK_9 = 57; public static final int VK_A = 65; + public static final int VK_D = 68; + public static final int VK_G = 71; public static final int VK_Z = 90; public static final int VK_NUMPAD0 = 96; public static final int VK_BACK_SLASH = 92; @@ -34,6 +36,7 @@ public class KeyboardTranslator implements InputManager.InputDeviceListener { public static final int VK_EQUALS = 61; public static final int VK_ESCAPE = 27; public static final int VK_F1 = 112; + public static final int VK_F11 = 122; public static final int VK_END = 35; public static final int VK_HOME = 36; public static final int VK_NUM_LOCK = 144; @@ -54,6 +57,8 @@ public class KeyboardTranslator implements InputManager.InputDeviceListener { public static final int VK_BACK_QUOTE = 192; public static final int VK_QUOTE = 222; public static final int VK_PAUSE = 19; + public static final int VK_LWIN = 91; + public static final int VK_LSHIFT = 160; private static class KeyboardMapping { private final InputDevice device; @@ -223,7 +228,7 @@ else if (keycode >= KeyEvent.KEYCODE_F1 && break; case KeyEvent.KEYCODE_META_LEFT: - translated = 0x5b; + translated = VK_LWIN; break; case KeyEvent.KEYCODE_META_RIGHT: @@ -271,7 +276,7 @@ else if (keycode >= KeyEvent.KEYCODE_F1 && break; case KeyEvent.KEYCODE_SHIFT_LEFT: - translated = 0xA0; + translated = VK_LSHIFT; break; case KeyEvent.KEYCODE_SHIFT_RIGHT: