From 81beb35809ae2bbc3df20d0ff96c65fa75dcab6e Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Wed, 24 Jul 2024 22:56:46 +0800 Subject: [PATCH] keyboard command test --- Limelight/Input/CommandManager.swift | 176 +++++++++++++++++- .../{Input => }/Moonlight-Bridging-Header.h | 1 + .../CommandManagerViewController.swift | 8 +- Moonlight.xcodeproj/project.pbxproj | 8 +- 4 files changed, 180 insertions(+), 13 deletions(-) rename Limelight/{Input => }/Moonlight-Bridging-Header.h (81%) diff --git a/Limelight/Input/CommandManager.swift b/Limelight/Input/CommandManager.swift index b778851f..3977f79d 100644 --- a/Limelight/Input/CommandManager.swift +++ b/Limelight/Input/CommandManager.swift @@ -51,12 +51,174 @@ import UIKit @objc public class CommandManager: NSObject { @objc public static let shared = CommandManager() - static let keyMappings: [String: UInt16] = [ - "CTRL": 0x11, - "ALT": 0x12, - "DEL": 0x2E, - "F1": 0x70, - "F2": 0x71 + static let keyMappings: [String: Int16] = [ + // Windows Key Codes + "CTRL": 0x11, // VK_CONTROL + "SHIFT": 0x10, // VK_SHIFT + "ALT": 0x12, // VK_MENU + "F1": 0x70, // VK_F1 + "F2": 0x71, // VK_F2 + "F3": 0x72, // VK_F3 + "F4": 0x73, // VK_F4 + "F5": 0x74, // VK_F5 + "F6": 0x75, // VK_F6 + "F7": 0x76, // VK_F7 + "F8": 0x77, // VK_F8 + "F9": 0x78, // VK_F9 + "F10": 0x79, // VK_F10 + "F11": 0x7A, // VK_F11 + "F12": 0x7B, // VK_F12 + "A": 0x41, // 'A' key + "B": 0x42, // 'B' key + "C": 0x43, // 'C' key + "D": 0x44, // 'D' key + "E": 0x45, // 'E' key + "F": 0x46, // 'F' key + "G": 0x47, // 'G' key + "H": 0x48, // 'H' key + "I": 0x49, // 'I' key + "J": 0x4A, // 'J' key + "K": 0x4B, // 'K' key + "L": 0x4C, // 'L' key + "M": 0x4D, // 'M' key + "N": 0x4E, // 'N' key + "O": 0x4F, // 'O' key + "P": 0x50, // 'P' key + "Q": 0x51, // 'Q' key + "R": 0x52, // 'R' key + "S": 0x53, // 'S' key + "T": 0x54, // 'T' key + "U": 0x55, // 'U' key + "V": 0x56, // 'V' key + "W": 0x57, // 'W' key + "X": 0x58, // 'X' key + "Y": 0x59, // 'Y' key + "Z": 0x5A, // 'Z' key + "0": 0x30, // '0' key + "1": 0x31, // '1' key + "2": 0x32, // '2' key + "3": 0x33, // '3' key + "4": 0x34, // '4' key + "5": 0x35, // '5' key + "6": 0x36, // '6' key + "7": 0x37, // '7' key + "8": 0x38, // '8' key + "9": 0x39, // '9' key + "ESC": 0x1B, // VK_ESCAPE + "SPACE": 0x20, // VK_SPACE + "ENTER": 0x0D, // VK_RETURN + "TAB": 0x09, // VK_TAB + "BACKSPACE": 0x08, // VK_BACK + "INSERT": 0x2D, // VK_INSERT + "DEL": 0x2E, // VK_DELETE + "HOME": 0x24, // VK_HOME + "END": 0x23, // VK_END + "PG_UP": 0x21, // VK_PRIOR + "PG_DOWN": 0x22, // VK_NEXT + "UP_ARROW": 0x26, // VK_UP + "DOWN_ARROW": 0x28, // VK_DOWN + "LEFT_ARROW": 0x25, // VK_LEFT + "RIGHT_ARROW": 0x27, // VK_RIGHT + "NUM_LCK": 0x90, // VK_NUMLOCK + "SCR_LCK": 0x91, // VK_SCROLL + "CAPS_LOCK": 0x14, // VK_CAPITAL + "PAUSE": 0x13, // VK_PAUSE + "PR_SCR": 0x2C, // VK_SNAPSHOT + "NUMPAD0": 0x60, // VK_NUMPAD0 + "NUMPAD1": 0x61, // VK_NUMPAD1 + "NUMPAD2": 0x62, // VK_NUMPAD2 + "NUMPAD3": 0x63, // VK_NUMPAD3 + "NUMPAD4": 0x64, // VK_NUMPAD4 + "NUMPAD5": 0x65, // VK_NUMPAD5 + "NUMPAD6": 0x66, // VK_NUMPAD6 + "NUMPAD7": 0x67, // VK_NUMPAD7 + "NUMPAD8": 0x68, // VK_NUMPAD8 + "NUMPAD9": 0x69, // VK_NUMPAD9 + "MULTIPLY": 0x6A, // VK_MULTIPLY + "ADD": 0x6B, // VK_ADD + "SUBTRACT": 0x6D, // VK_SUBTRACT + "DECIMAL": 0x6E, // VK_DECIMAL + "DIVIDE": 0x6F, // VK_DIVIDE + "SEMI_COLON": 0xBA, // VK_OEM_1 + "EQUALS": 0xBB, // VK_OEM_PLUS + "COMMA": 0xBC, // VK_OEM_COMMA + "MINUS": 0xBD, // VK_OEM_MINUS + "PERIOD": 0xBE, // VK_OEM_PERIOD + "FORWARD_SLASH": 0xBF, // VK_OEM_2 + "GRAVE_ACCENT": 0xC0, // VK_OEM_3 + "OPEN_BRACKET": 0xDB, // VK_OEM_4 + "BACKSLASH": 0xDC, // VK_OEM_5 + "CLOSE_BRACKET": 0xDD, // VK_OEM_6 + "SINGLE_QUOTE": 0xDE, // VK_OEM_7 + "VOLUME_MUTE": 0xAD, // VK_VOLUME_MUTE + "VOLUME_DOWN": 0xAE, // VK_VOLUME_DOWN + "VOLUME_UP": 0xAF, // VK_VOLUME_UP + "MEDIA_NEXT": 0xB0, // VK_MEDIA_NEXT_TRACK + "MEDIA_PREV": 0xB1, // VK_MEDIA_PREV_TRACK + "MEDIA_STOP": 0xB2, // VK_MEDIA_STOP + "MEDIA_PLAY_PAUSE": 0xB3, // VK_MEDIA_PLAY_PAUSE + "LAUNCH_MAIL": 0xB4, // VK_LAUNCH_MAIL + "LAUNCH_MEDIA_SELECT": 0xB5, // VK_LAUNCH_MEDIA_SELECT + "LAUNCH_APP1": 0xB6, // VK_LAUNCH_APP1 + "LAUNCH_APP2": 0xB7, // VK_LAUNCH_APP2 + "WIN": 0x5B, + "LEFT_WIN": 0x5B, // VK_LWIN + "RIGHT_WIN": 0x5C, // VK_RWIN + "APPS": 0x5D, // VK_APPS + + // macOS Key Codes + "CMD": 0x37, // ⌘ Command + "OPT": 0x3A, // ⌥ Option + "CONTROL": 0x3B, // ⌃ Control + "SHIFT_MAC": 0x38, // ⇧ Shift + "FUNCTION": 0x3F, // fn + "DELETE_MAC": 0x75, // Forward Delete + "RETURN_MAC": 0x24, // Return + "ENTER_MAC": 0x4C, // Enter + "ESCAPE_MAC": 0x35, // Escape + "TAB_MAC": 0x30, // Tab + "SPACE_MAC": 0x31, // Space + "UP_ARROW_MAC": 0x7E, // Up Arrow + "DOWN_ARROW_MAC": 0x7D, // Down Arrow + "LEFT_ARROW_MAC": 0x7B, // Left Arrow + "RIGHT_ARROW_MAC": 0x7C, // Right Arrow + "F1_MAC": 0x7A, // F1 + "F2_MAC": 0x78, // F2 + "F3_MAC": 0x63, // F3 + "F4_MAC": 0x76, // F4 + "F5_MAC": 0x60, // F5 + "F6_MAC": 0x61, // F6 + "F7_MAC": 0x62, // F7 + "F8_MAC": 0x64, // F8 + "F9_MAC": 0x65, // F9 + "F10_MAC": 0x6D, // F10 + "F11_MAC": 0x67, // F11 + "F12_MAC": 0x6F, // F12 + "0_MAC": 0x52, // 0 + "1_MAC": 0x53, // 1 + "2_MAC": 0x54, // 2 + "3_MAC": 0x55, // 3 + "4_MAC": 0x56, // 4 + "5_MAC": 0x57, // 5 + "6_MAC": 0x58, // 6 + "7_MAC": 0x59, // 7 + "8_MAC": 0x5A, // 8 + "9_MAC": 0x5B, // 9 + "NUMPAD0_MAC": 0x4F, // Numpad 0 + "NUMPAD1_MAC": 0x50, // Numpad 1 + "NUMPAD2_MAC": 0x51, // Numpad 2 + "NUMPAD3_MAC": 0x52, // Numpad 3 + "NUMPAD4_MAC": 0x53, // Numpad 4 + "NUMPAD5_MAC": 0x54, // Numpad 5 + "NUMPAD6_MAC": 0x55, // Numpad 6 + "NUMPAD7_MAC": 0x56, // Numpad 7 + "NUMPAD8_MAC": 0x57, // Numpad 8 + "NUMPAD9_MAC": 0x58, // Numpad 9 + "NUMPAD_ADD_MAC": 0x45, // Numpad Add + "NUMPAD_SUBTRACT_MAC": 0x4A, // Numpad Subtract + "NUMPAD_MULTIPLY_MAC": 0x43, // Numpad Multiply + "NUMPAD_DIVIDE_MAC": 0x4B, // Numpad Divide + "NUMPAD_DECIMAL_MAC": 0x41, // Numpad Decimal ] private var commands: [RemoteCommand] = [] @@ -68,7 +230,7 @@ import UIKit loadCommands() } - @objc public func createTestKeyMappings() -> [String: UInt16] { + @objc public func createTestKeyMappings() -> [String: Int16] { return CommandManager.keyMappings } diff --git a/Limelight/Input/Moonlight-Bridging-Header.h b/Limelight/Moonlight-Bridging-Header.h similarity index 81% rename from Limelight/Input/Moonlight-Bridging-Header.h rename to Limelight/Moonlight-Bridging-Header.h index 1b2cb5d6..05482595 100644 --- a/Limelight/Input/Moonlight-Bridging-Header.h +++ b/Limelight/Moonlight-Bridging-Header.h @@ -2,3 +2,4 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // +#include diff --git a/Limelight/ViewControllers/CommandManagerViewController.swift b/Limelight/ViewControllers/CommandManagerViewController.swift index 81623b0d..3c389948 100644 --- a/Limelight/ViewControllers/CommandManagerViewController.swift +++ b/Limelight/ViewControllers/CommandManagerViewController.swift @@ -244,13 +244,17 @@ import UIKit if !isEditingMode { // Call the dummy method for key-value sending implementation - dummyMethodForKeySending() + sendKeyboardCommand() dismiss(animated: false, completion: nil) // dimiss the view in sending mode } } - private func dummyMethodForKeySending() { + private func sendKeyboardCommand() { // Dummy implementation print("Sending key-value") + LiSendKeyboardEvent(CommandManager.keyMappings["WIN"]!,Int8(KEY_ACTION_DOWN), 0) + Thread.sleep(forTimeInterval: 0.05) + LiSendKeyboardEvent(CommandManager.keyMappings["WIN"]!,Int8(KEY_ACTION_UP), 0) } } + diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 2baf0c8b..f425804b 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -153,6 +153,7 @@ 8454AC6D2C319BDA00F0A302 /* mul */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; name = mul; path = mul.lproj/iPhone.xcstrings; sourceTree = ""; }; 84591A4F2BE16240006AAB10 /* CustomEdgeSwipeGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomEdgeSwipeGestureRecognizer.h; sourceTree = ""; }; 84591A502BE1625E006AAB10 /* CustomEdgeSwipeGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomEdgeSwipeGestureRecognizer.m; sourceTree = ""; }; + 84D8EB932C5146AD00FC10A9 /* Moonlight-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Moonlight-Bridging-Header.h"; sourceTree = ""; }; 84E1CDEB2C4F67D300547904 /* CommandManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandManager.swift; sourceTree = ""; }; 84E1CDEE2C4F688E00547904 /* CommandManagerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandManagerViewController.swift; sourceTree = ""; }; 84E1CDF92C4FE83400547904 /* SwiftLocalizationHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftLocalizationHelper.swift; sourceTree = ""; }; @@ -200,7 +201,6 @@ 98D5856C1C0EA79600F6CC00 /* TemporaryHost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TemporaryHost.m; path = Database/TemporaryHost.m; sourceTree = ""; }; 98D5856E1C0ED0E800F6CC00 /* TemporarySettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TemporarySettings.h; path = Database/TemporarySettings.h; sourceTree = ""; }; 98D5856F1C0ED0E800F6CC00 /* TemporarySettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TemporarySettings.m; path = Database/TemporarySettings.m; sourceTree = ""; }; - D4746EEA1CBC740C006FB401 /* Moonlight-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Moonlight-Bridging-Header.h"; path = "Input/Moonlight-Bridging-Header.h"; sourceTree = ""; }; DC1F5A05206436B10037755F /* ConnectionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConnectionHelper.h; sourceTree = ""; }; DC1F5A06206436B20037755F /* ConnectionHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConnectionHelper.m; sourceTree = ""; }; FB1A674B2131E65900507771 /* KeyboardSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyboardSupport.h; sourceTree = ""; }; @@ -539,10 +539,10 @@ FB290CF919B2C406004C83CF /* Moonlight */ = { isa = PBXGroup; children = ( + 84D8EB932C5146AD00FC10A9 /* Moonlight-Bridging-Header.h */, 84FD0B492C312C0B006B5BE5 /* Localization */, 8454AC682C31907F00F0A302 /* iPad.storyboard */, 8454AC6C2C319BDA00F0A302 /* iPhone.storyboard */, - D4746EEA1CBC740C006FB401 /* Moonlight-Bridging-Header.h */, FB89460419F646E200339C8A /* Crypto */, FB89460919F646E200339C8A /* Input */, FB89460E19F646E200339C8A /* Network */, @@ -1278,7 +1278,7 @@ PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; SKIP_INSTALL = NO; - SWIFT_OBJC_BRIDGING_HEADER = "Limelight/Input/Moonlight-Bridging-Header.h"; + SWIFT_OBJC_BRIDGING_HEADER = "Limelight/Moonlight-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = "Moonlight-Swift.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; @@ -1336,7 +1336,7 @@ PROVISIONING_PROFILE = ""; SKIP_INSTALL = NO; SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OBJC_BRIDGING_HEADER = "Limelight/Input/Moonlight-Bridging-Header.h"; + SWIFT_OBJC_BRIDGING_HEADER = "Limelight/Moonlight-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = "Moonlight-Swift.h"; SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_SWIFT3_OBJC_INFERENCE = Default;