-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back menu to send sepcial keys. E.g. close fullscreen while using yuzu.
- Loading branch information
Karim Mreisi
committed
Jan 15, 2023
1 parent
b8904bb
commit b6097d3
Showing
2 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.limelight; | ||
|
||
import android.app.AlertDialog; | ||
import android.widget.ArrayAdapter; | ||
|
||
import com.limelight.nvstream.NvConnection; | ||
import com.limelight.nvstream.input.KeyboardPacket; | ||
|
||
public class GameBackMenu { | ||
|
||
private final Game game; | ||
private final NvConnection conn; | ||
|
||
public GameBackMenu(Game game, NvConnection conn) { | ||
this.game = game; | ||
this.conn = conn; | ||
|
||
showMenuDialog("Back Menu", new MenuDialogOption[]{ | ||
new MenuDialogOption("Send special key(s)", () -> showSpecialKeysMenu()), | ||
new MenuDialogOption("Disconnect", () -> game.onBackPressed()), | ||
new MenuDialogOption("Cancel", null), | ||
}); | ||
} | ||
|
||
private void sendKeySequence(byte modifier, short[] keys) { | ||
|
||
for (short key : keys) | ||
conn.sendKeyboardInput(key, KeyboardPacket.KEY_DOWN, (byte) (modifier | KeyboardPacket.KEY_DOWN)); | ||
|
||
for (int pos = keys.length - 1; pos >= 0; pos--) | ||
conn.sendKeyboardInput(keys[pos], KeyboardPacket.KEY_UP, (byte) (modifier | KeyboardPacket.KEY_UP)); | ||
} | ||
|
||
private void showMenuDialog(String title, MenuDialogOption[] options) { | ||
AlertDialog.Builder builder = new AlertDialog.Builder(game); | ||
builder.setTitle(title); | ||
|
||
final ArrayAdapter<String> actions = | ||
new ArrayAdapter<String>(game, android.R.layout.simple_list_item_1); | ||
|
||
for (MenuDialogOption option : options) { | ||
actions.add(option.label); | ||
} | ||
|
||
builder.setAdapter(actions, (dialog, which) -> { | ||
String label = actions.getItem(which); | ||
for (MenuDialogOption option : options) { | ||
if (!label.equals(option.label)) { | ||
continue; | ||
} | ||
|
||
if (option.runnable != null) { | ||
option.runnable.run(); | ||
} | ||
break; | ||
} | ||
}); | ||
|
||
builder.show(); | ||
} | ||
|
||
private void showSpecialKeysMenu() { | ||
showMenuDialog(ACTIONS.SEND_SPECIAL_KEYS, new MenuDialogOption[]{ | ||
new MenuDialogOption("Send ESC", () -> sendKeySequence( | ||
(byte) 0, new short[]{0x18})), | ||
new MenuDialogOption("Send F11", () -> sendKeySequence( | ||
(byte) 0, new short[]{0x7a})), | ||
new MenuDialogOption("Send WIN (Open Start Menu)", () -> sendKeySequence( | ||
(byte) 0, new short[]{0x5B})), | ||
new MenuDialogOption("Send WIN + D (Switch to Desktop)", () -> sendKeySequence( | ||
(byte) 0, new short[]{0x5B, 0x44})), | ||
new MenuDialogOption("Send WIN + G (Open Xbox Game Bar)", () -> sendKeySequence( | ||
(byte) 0, new short[]{0x5B, 0x47})), | ||
/* | ||
TODO: Currently not working | ||
new MenuDialogOption("Send SHIFT + TAB (Open Steam Overlay)", () -> sendKeySequence( | ||
(byte) 0, new short[]{0xA0, 0x09})), | ||
*/ | ||
new MenuDialogOption("Cancel", null), | ||
}); | ||
} | ||
|
||
private interface ACTIONS { | ||
String CONTINUE = "Continue"; | ||
String SEND_SPECIAL_KEYS = "Send special key(s)"; | ||
String DISCONNECT = "Disconnect"; | ||
} | ||
|
||
private class MenuDialogOption { | ||
private final String label; | ||
private final Runnable runnable; | ||
|
||
MenuDialogOption(String label, Runnable runnable) { | ||
this.label = label; | ||
this.runnable = runnable; | ||
} | ||
} | ||
} |