From c9a5cea93e4a80fa595c9d87c4f06085b920760b Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Mon, 16 Jan 2023 21:05:11 -0600 Subject: [PATCH] Add Sunshine protocol extension to support non-normalized key codes --- src/Input.h | 2 +- src/InputStream.c | 8 ++++++-- src/Limelight.h | 8 ++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Input.h b/src/Input.h index 4cc2029..3c0681b 100644 --- a/src/Input.h +++ b/src/Input.h @@ -17,7 +17,7 @@ typedef struct _NV_HAPTICS_PACKET { #define KEY_UP_EVENT_MAGIC 0x00000004 typedef struct _NV_KEYBOARD_PACKET { NV_INPUT_HEADER header; - char zero1; + char flags; // Sunshine extension (always 0 for GFE) short keyCode; char modifiers; short zero2; diff --git a/src/InputStream.c b/src/InputStream.c index 523461f..7dc0546 100644 --- a/src/InputStream.c +++ b/src/InputStream.c @@ -675,7 +675,7 @@ int LiSendMouseButtonEvent(char action, int button) { } // Send a key press event to the streaming machine -int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) { +int LiSendKeyboardEvent2(short keyCode, char keyAction, char modifiers, char flags) { PPACKET_HOLDER holder; int err; @@ -732,7 +732,7 @@ int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) { holder->packet.keyboard.header.size = BE32(sizeof(NV_KEYBOARD_PACKET) - sizeof(uint32_t)); holder->packet.keyboard.header.magic = LE32((uint32_t)keyAction); - holder->packet.keyboard.zero1 = 0; + holder->packet.keyboard.flags = IS_SUNSHINE() ? flags : 0; holder->packet.keyboard.keyCode = LE16(keyCode); holder->packet.keyboard.modifiers = modifiers; holder->packet.keyboard.zero2 = 0; @@ -747,6 +747,10 @@ int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) { return err; } +int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers) { + return LiSendKeyboardEvent2(keyCode, keyAction, modifiers, 0); +} + int LiSendUtf8TextEvent(const char *text, unsigned int length) { PPACKET_HOLDER holder; int err; diff --git a/src/Limelight.h b/src/Limelight.h index 8ce50a8..06d474d 100644 --- a/src/Limelight.h +++ b/src/Limelight.h @@ -546,6 +546,8 @@ int LiSendMouseMoveAsMousePositionEvent(short deltaX, short deltaY, short refere int LiSendMouseButtonEvent(char action, int button); // This function queues a keyboard event to be sent to the remote server. +// Key codes are Win32 Virtual Key (VK) codes and interpreted as keys on +// a US English layout. #define KEY_ACTION_DOWN 0x03 #define KEY_ACTION_UP 0x04 #define MODIFIER_SHIFT 0x01 @@ -554,6 +556,12 @@ int LiSendMouseButtonEvent(char action, int button); #define MODIFIER_META 0x08 int LiSendKeyboardEvent(short keyCode, char keyAction, char modifiers); +// Similar to LiSendKeyboardEvent() but allows the client to inform the host that +// the keycode was not mapped to a standard US English scancode and should be +// interpreted as-is. This is a Sunshine protocol extension. +#define SS_KBE_FLAG_NON_NORMALIZED 0x01 +int LiSendKeyboardEvent2(short keyCode, char keyAction, char modifiers, char flags); + // This function queues an UTF-8 encoded text to be sent to the remote server. int LiSendUtf8TextEvent(const char *text, unsigned int length);