Skip to content

Commit

Permalink
game menu: cleanup + fix steam overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Karim Mreisi committed Jan 21, 2023
1 parent 1985ca5 commit 0931adf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
52 changes: 29 additions & 23 deletions app/src/main/java/com/limelight/GameMenu.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>
* 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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0931adf

Please sign in to comment.