diff --git a/Limelight/Input/CommandManager.swift b/Limelight/Input/CommandManager.swift index 8b9de3a9..8eb71255 100644 --- a/Limelight/Input/CommandManager.swift +++ b/Limelight/Input/CommandManager.swift @@ -165,7 +165,7 @@ import UIKit "LEFT_WIN": 0x5B, // VK_LWIN "RIGHT_WIN": 0x5C, // VK_RWIN "APPS": 0x5D, // VK_APPS - + // macOS Key Codes "CMD": 0x37, // ⌘ Command "OPT": 0x3A, // ⌥ Option @@ -222,7 +222,7 @@ import UIKit ] private var commands: [RemoteCommand] = [] - + public weak var viewController: CommandManagerViewController? private override init() { @@ -255,7 +255,7 @@ import UIKit defaults.set(data, forKey: "savedCommands") } } - + @objc public func createTestKeyMappings() -> [String: Int16] { return CommandManager.keyMappings } @@ -278,7 +278,7 @@ import UIKit let matchedString = (input as NSString).substring(with: match.range(at: 0)) let keyStrings = matchedString.split(separator: "+").map { String($0) } - + guard !keyStrings.isEmpty else { print("No key strings found in the matched string") return nil @@ -305,7 +305,7 @@ import UIKit } return validKeyStrings - + } @objc public func addCommand(_ command: RemoteCommand) -> Bool { @@ -349,11 +349,33 @@ import UIKit } } } - + private func saveCommands() { if let data = try? NSKeyedArchiver.archivedData(withRootObject: commands, requiringSecureCoding: false) { UserDefaults.standard.set(data, forKey: "savedCommands") } } + + @objc public func sendKeyDownEventWithDelay(keyboardCmdStrings: [String], delay: TimeInterval = 0.05, index: Int = 0) { + guard index < keyboardCmdStrings.count else { + for keyStr in keyboardCmdStrings { + LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_UP), 0) + } + return + } // 如果已经处理完所有键,释放所有按键 + + let keyCode = CommandManager.keyMappings[keyboardCmdStrings[index]] + guard let keyCode = keyCode else { + print("No mapping found for \(keyboardCmdStrings[index])") + sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 + return + } + // 发送当前键的键盘按下事件 + LiSendKeyboardEvent(keyCode,Int8(KEY_ACTION_DOWN), 0) + // 使用 asyncAfter 在指定异步延迟后发送下一个键的键盘按下事件 + DispatchQueue.main.asyncAfter(deadline: .now() + delay) { + self.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 + } + } } diff --git a/Limelight/Input/CustomOSC/OSCProfilesManager.m b/Limelight/Input/CustomOSC/OSCProfilesManager.m index 3015f14e..790aaef3 100644 --- a/Limelight/Input/CustomOSC/OSCProfilesManager.m +++ b/Limelight/Input/CustomOSC/OSCProfilesManager.m @@ -200,6 +200,50 @@ static NSMutableDictionary *onScreenKeyViewsDict; - (bool) updateSelectedProfile:(NSMutableArray *) oscButtonLayers { + NSMutableArray* buttonStatesEncoded = [self convertOnscreenButtonsToButtonStates:oscButtonLayers]; + if([self getIndexOfSelectedProfile]==0) return false; + OSCProfile *newProfile = [[OSCProfile alloc] initWithName:[self getSelectedProfile].name + buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view + + + /* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */ + NSMutableArray *profiles = [self getAllProfiles]; + for (OSCProfile *profile in profiles) { + profile.isSelected = NO; + } + [self replaceProfile:[self getSelectedProfile] withProfile:newProfile]; + return true; +} + + +- (void) saveProfileWithName:(NSString*)name andButtonLayers:(NSMutableArray *)oscButtonLayers { + NSMutableArray* buttonStatesEncoded = [self convertOnscreenButtonsToButtonStates:oscButtonLayers]; + OSCProfile *newProfile = [[OSCProfile alloc] initWithName:name + buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view + /* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */ + NSMutableArray *profiles = [self getAllProfiles]; + for (OSCProfile *profile in profiles) { + + profile.isSelected = NO; + } + + if ([self profileNameAlreadyExist:name]) { // if a saved profile with the same 'name' already exists in persistent storage then overwrite it and save the change to persistent storage + [self replaceProfile:[self OSCProfileWithName:name] withProfile:newProfile]; + } + else { // otherwise encode then add the new profile to the end of the OSCProfiles array + NSData *newProfileEncoded = [NSKeyedArchiver archivedDataWithRootObject:newProfile requiringSecureCoding:YES error:nil]; + NSMutableArray *profilesEncoded = [self encodedProfilesFromArray:profiles]; + [profilesEncoded addObject:newProfileEncoded]; + + /* Encode the 'profilesEncoded' array itself, NOT the objects in the 'profilesEncoded' array, all of which are already encoded by this point */ + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil]; + [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } +} + + +- (NSMutableArray* ) convertOnscreenButtonsToButtonStates:(NSMutableArray *) oscButtonLayers { /* iterate through each OSC button the user sees on screen, create an 'OnScreenButtonState' object from each button, encode each object, and then add each object to an array */ /* NSSet *validPositionButtonNames = [NSSet setWithObjects: @@ -223,102 +267,24 @@ static NSMutableDictionary *onScreenKeyViewsDict; OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:oscButtonLayer.name buttonType:GameControllerButton andPosition:oscButtonLayer.position]; // add hidden attr here buttonState.isHidden = oscButtonLayer.isHidden; - - /* //------------------------------------- - NSLog(@"buttonName to be saved: %@", buttonState.name); - if([validPositionButtonNames containsObject:buttonState.name]) buttonState.hasValidPosition = true; // this is for setting up DZ for custom OSC buttons. - else buttonState.hasValidPosition = false; - //------------------------------------- */ NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil]; [buttonStatesEncoded addObject: buttonStateEncoded]; } - // save keyboard button as buttonstate + // save keyboard button as buttonstate, this is for the new onscreen keyboard buttons: [onScreenKeyViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { // this dict is passed from the layout tool VC, as a static obj in this class. - OnScreenKeyView *keyView = value; + OnScreenKeyboardButtonView *keyView = value; OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:keyView.keyString buttonType:KeyboardButton andPosition:keyView.frame.origin]; buttonState.alias = keyView.keyLabel; buttonState.timestamp = keyView.timestamp; NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil]; [buttonStatesEncoded addObject: buttonStateEncoded]; }]; - - - - if([self getIndexOfSelectedProfile]==0) return false; - OSCProfile *newProfile = [[OSCProfile alloc] initWithName:[self getSelectedProfile].name - buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view - - - /* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */ - NSMutableArray *profiles = [self getAllProfiles]; - for (OSCProfile *profile in profiles) { - profile.isSelected = NO; - } - [self replaceProfile:[self getSelectedProfile] withProfile:newProfile]; - return true; + return buttonStatesEncoded; } -- (void) saveProfileWithName:(NSString*)name andButtonLayers:(NSMutableArray *)buttonLayers { - /* iterate through each OSC button the user sees on screen, create an 'OnScreenButtonState' object from each button, encode each object, and then add each object to an array */ - /* - NSSet *validPositionButtonNames = [NSSet setWithObjects: - @"l2Button", - @"l1Button", - @"dPad", - @"selectButton", - @"leftStickBackground", - @"rightStickBackground", - @"r2Button", - @"r1Button", - @"aButton", - @"bButton", - @"xButton", - @"yButton", - @"startButton", - nil]; */ - NSMutableArray *buttonStatesEncoded = [[NSMutableArray alloc] init]; - for (CALayer *buttonLayer in buttonLayers) { - OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:buttonLayer.name buttonType:GameControllerButton andPosition:buttonLayer.position]; - // add hidden attr here - buttonState.isHidden = buttonLayer.isHidden; - /* //------------------------------------- - NSLog(@"buttonName to be saved: %@", buttonState.name); - if([validPositionButtonNames containsObject:buttonState.name]) buttonState.hasValidPosition = true; // this is for setting up DZ for custom OSC buttons. - else buttonState.hasValidPosition = false; - //------------------------------------- */ - NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil]; - [buttonStatesEncoded addObject: buttonStateEncoded]; - } - - OSCProfile *newProfile = [[OSCProfile alloc] initWithName:name - buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view - - - /* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */ - NSMutableArray *profiles = [self getAllProfiles]; - for (OSCProfile *profile in profiles) { - - profile.isSelected = NO; - } - - if ([self profileNameAlreadyExist:name]) { // if a saved profile with the same 'name' already exists in persistent storage then overwrite it and save the change to persistent storage - [self replaceProfile:[self OSCProfileWithName:name] withProfile:newProfile]; - } - else { // otherwise encode then add the new profile to the end of the OSCProfiles array - NSData *newProfileEncoded = [NSKeyedArchiver archivedDataWithRootObject:newProfile requiringSecureCoding:YES error:nil]; - NSMutableArray *profilesEncoded = [self encodedProfilesFromArray:profiles]; - [profilesEncoded addObject:newProfileEncoded]; - - /* Encode the 'profilesEncoded' array itself, NOT the objects in the 'profilesEncoded' array, all of which are already encoded by this point */ - NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil]; - [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"]; - [[NSUserDefaults standardUserDefaults] synchronize]; - } -} - #pragma mark - Queries - (BOOL) profileNameAlreadyExist:(NSString*)name { diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index 0389c14c..08e39f87 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -256,7 +256,7 @@ static float L3_Y; - (void) updateControls { if(self._level == OnScreenControlsLevelCustom){ - // these buttons that has valid coords of positions + // mark all OSC buttons that has valid coords of positions NSSet *validPositionButtonNames = [NSSet setWithObjects: @"l2Button", @"l1Button", @@ -286,9 +286,10 @@ static float L3_Y; } } NSLog(@"_activeCustomOscButtonPositionDict update, active button number: %lu", (unsigned long)[_activeCustomOscButtonPositionDict count]); - } + + // belows are orginal codes: switch (self._level) { case OnScreenControlsLevelOff: [self hideButtons]; diff --git a/Limelight/Input/OnScreenKeyView.swift b/Limelight/Input/OnScreenKeyboardButtonView.swift similarity index 66% rename from Limelight/Input/OnScreenKeyView.swift rename to Limelight/Input/OnScreenKeyboardButtonView.swift index 29bb7b6c..ab3c2573 100644 --- a/Limelight/Input/OnScreenKeyView.swift +++ b/Limelight/Input/OnScreenKeyboardButtonView.swift @@ -9,7 +9,7 @@ import UIKit -@objc class OnScreenKeyView: UIView { +@objc class OnScreenKeyboardButtonView: UIView { @objc static public var editMode: Bool = false @objc static public var timestampOfButtonBeingDragged: TimeInterval = 0 @objc public var keyLabel: String @@ -42,37 +42,50 @@ import UIKit } @objc public func enableRelocationMode(enabled: Bool){ - OnScreenKeyView.editMode = enabled + OnScreenKeyboardButtonView.editMode = enabled } private func setupView() { label.text = self.keyLabel - label.font = UIFont.systemFont(ofSize: 22) - label.textColor = UIColor(white: 1.0, alpha: 0.8) - label.shadowColor = .black + //label.font = UIFont.systemFont(ofSize: 28) label.translatesAutoresizingMaskIntoConstraints = false + label.adjustsFontSizeToFitWidth = true + label.minimumScaleFactor = 0.1 // Adjust the scale factor as needed + + label.textColor = UIColor(white: 1.0, alpha: 0.9) + label.textAlignment = .center + label.shadowColor = .black + label.shadowOffset = CGSize(width: 1, height: 1) + label.translatesAutoresizingMaskIntoConstraints = false // enable auto alignment for the label self.translatesAutoresizingMaskIntoConstraints = true // this is mandatory to prevent unexpected key view location change self.layer.borderColor = UIColor.black.cgColor - self.layer.borderWidth = 2 - self.layer.cornerRadius = 8 - self.backgroundColor = UIColor(white: 0.2, alpha: 0.7) - self.layer.shadowRadius = 4 + self.layer.borderWidth = 0 + self.layer.cornerRadius = 16 + self.backgroundColor = UIColor(white: 0.2, alpha: 0.5) + self.layer.shadowColor = UIColor.clear.cgColor + self.layer.shadowRadius = 8 self.layer.shadowOpacity = 0.5 addSubview(label) - NSLayoutConstraint.activate([ - label.centerXAnchor.constraint(equalTo: centerXAnchor), - label.centerYAnchor.constraint(equalTo: centerYAnchor), - ]) NSLayoutConstraint.activate([ //self.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width * 0.088), //self.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height * 0.1), - self.widthAnchor.constraint(equalToConstant: 85), + self.widthAnchor.constraint(equalToConstant: 75), self.heightAnchor.constraint(equalToConstant: 65), ]) + + NSLayoutConstraint.activate([ + label.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: 5), + label.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -5), + label.centerXAnchor.constraint(equalTo: centerXAnchor), + label.centerYAnchor.constraint(equalTo: centerYAnchor), + //label.heightAnchor.constraint(equalToConstant: 40) + ]) + + } // Touch event handling @@ -80,10 +93,21 @@ import UIKit super.touchesBegan(touches, with: event) //self.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.7) - - if !OnScreenKeyView.editMode { + if !OnScreenKeyboardButtonView.editMode { self.backgroundColor = UIColor.systemBlue.withAlphaComponent(0.7) - LiSendKeyboardEvent(CommandManager.keyMappings[self.keyString]!,Int8(KEY_ACTION_DOWN), 0) + + // if the command(keystring contains "+", it's a multi-key command or a quick triggering key, rather than a physical button + if(self.keyString.contains("+")){ + let keyboardCmdStrings = CommandManager.shared.extractKeyStrings(from: self.keyString)! + CommandManager.shared.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings) // send multi-key command + DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { // reset background color immediately 50ms later + self.backgroundColor = self.originalBackgroundColor + } + } + // if there's no "+" in the keystring, treat it as a regular button: + else{ + LiSendKeyboardEvent(CommandManager.keyMappings[self.keyString]!,Int8(KEY_ACTION_DOWN), 0) + } } else { if let touch = touches.first { @@ -96,10 +120,10 @@ import UIKit override func touchesMoved(_ touches: Set, with event: UIEvent?) { super.touchesMoved(touches, with: event) - OnScreenKeyView.timestampOfButtonBeingDragged = self.timestamp + OnScreenKeyboardButtonView.timestampOfButtonBeingDragged = self.timestamp // Move the KeyView based on touch movement in relocation mode - if OnScreenKeyView.editMode { + if OnScreenKeyboardButtonView.editMode { if let touch = touches.first { let currentLocation = touch.location(in: superview) let offsetX = currentLocation.x - storedLocation.x @@ -115,9 +139,9 @@ import UIKit override func touchesEnded(_ touches: Set, with event: UIEvent?) { super.touchesEnded(touches, with: event) - if !OnScreenKeyView.editMode { + if !OnScreenKeyboardButtonView.editMode && !self.keyString.contains("+") { // if the command(keystring contains "+", it's a multi-key command rather than a single key button LiSendKeyboardEvent(CommandManager.keyMappings[self.keyString]!,Int8(KEY_ACTION_UP), 0) - return + self.backgroundColor = self.originalBackgroundColor } self.backgroundColor = self.originalBackgroundColor diff --git a/Limelight/Input/StreamView.h b/Limelight/Input/StreamView.h index abf46c5e..8cdb4bc1 100644 --- a/Limelight/Input/StreamView.h +++ b/Limelight/Input/StreamView.h @@ -34,6 +34,9 @@ andConfig:(StreamConfiguration*)streamConfig; - (void) reloadOnScreenControlsWith:(ControllerSupport*)controllerSupport andConfig:(StreamConfiguration*)streamConfig; +- (void) clearOnScreenKeyboardButtons; +- (void) reloadOnScreenKeyboardButtons; + - (CGSize) getVideoAreaSize; - (CGPoint) adjustCoordinatesForVideoArea:(CGPoint)point; - (uint16_t)getRotationFromAzimuthAngle:(float)azimuthAngle; diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index aee2500d..264bec0d 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -11,6 +11,8 @@ #import "DataManager.h" #import "ControllerSupport.h" #import "KeyboardSupport.h" +#import "Moonlight-Swift.h" +#import "OSCProfilesManager.h" #import "NativeTouchPointer.h" #import "NativeTouchHandler.h" #import "RelativeTouchHandler.h" @@ -327,7 +329,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; - (void) reloadOnScreenControlsWith:(ControllerSupport*)controllerSupport andConfig:(StreamConfiguration*)streamConfig { onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport streamConfig:streamConfig]; - /* // pass mouseRightClickTapRecognizer to onScreenControls obj here: if([self isOscEnabled]){ @@ -338,6 +339,45 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; [onScreenControls setLevel:(OnScreenControlsLevel)settings.onscreenControls.intValue]; } + +- (void) clearOnScreenKeyboardButtons{ + for (UIView *subview in self.superview.subviews) { + // 检查子视图是否是特定类型的实例 + if ([subview isKindOfClass:[OnScreenKeyboardButtonView class]]) { + // 如果是,就添加到将要被移除的数组中 + [subview removeFromSuperview]; + } + } +} + +- (void) reloadOnScreenKeyboardButtons{ + + NSLog(@"reload on screen keyboard buttons here"); + + // remove all keyboard button views first + [self clearOnScreenKeyboardButtons]; + + bool customOscEnabled = (settings.touchMode.intValue == RELATIVE_TOUCH || settings.touchMode.intValue == REGULAR_NATIVE_TOUCH) && settings.onscreenControls.intValue == OnScreenControlsLevelCustom; + + if(!customOscEnabled) return; //returns if we're not in custom osc mode + + OSCProfilesManager* profilesManager = [OSCProfilesManager sharedManager]; + OSCProfile *oscProfile = [profilesManager getSelectedProfile]; //returns the currently selected OSCProfile + + if(!OnScreenKeyboardButtonView.editMode){ // in edit mode, keyboard button view will be updated within layoutool view controller. + for (NSData *buttonStateEncoded in oscProfile.buttonStates) { + OnScreenButtonState* buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil]; + if(buttonState.buttonType == KeyboardButton){ + OnScreenKeyboardButtonView* keyView = [[OnScreenKeyboardButtonView alloc] initWithKeyString:buttonState.name keyLabel:buttonState.alias]; //reconstruct keyView + keyView.translatesAutoresizingMaskIntoConstraints = NO; // weird but this is mandatory, or you will find no key views added to the right place + // Add the KeyView to the view controller's view + [self.superview addSubview:keyView]; // add keyboard button to the stream frame view. must add it to the target view before setting location. + [keyView setKeyLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y]; + } + } + } +} + - (OnScreenControlsLevel) getCurrentOscState { if (onScreenControls == nil) { return OnScreenControlsLevelOff; @@ -347,6 +387,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; } } + - (CGSize) getVideoAreaSize { if (self.bounds.size.width > self.bounds.size.height * streamAspectRatio) { return CGSizeMake(self.bounds.size.height * streamAspectRatio, self.bounds.size.height); diff --git a/Limelight/ViewControllers/CommandManagerViewController.swift b/Limelight/ViewControllers/CommandManagerViewController.swift index d854c929..adf0fdfa 100644 --- a/Limelight/ViewControllers/CommandManagerViewController.swift +++ b/Limelight/ViewControllers/CommandManagerViewController.swift @@ -304,29 +304,7 @@ import UIKit private func sendKeyboardCommand(_ cmd: RemoteCommand) { print("Sending key-value") let keyboardCmdStrings = CommandManager.shared.extractKeyStrings(from: cmd.keyboardCmdString) - sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings!) - } - - private func sendKeyDownEventWithDelay(keyboardCmdStrings: [String], delay: TimeInterval = 0.05, index: Int = 0) { - guard index < keyboardCmdStrings.count else { - for keyStr in keyboardCmdStrings { - LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_UP), 0) - } - return - } // 如果已经处理完所有键,释放所有按键 - - let keyCode = CommandManager.keyMappings[keyboardCmdStrings[index]] - guard let keyCode = keyCode else { - print("No mapping found for \(keyboardCmdStrings[index])") - sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 - return - } - // 发送当前键的键盘按下事件 - LiSendKeyboardEvent(keyCode,Int8(KEY_ACTION_DOWN), 0) - // 使用 asyncAfter 在指定异步延迟后发送下一个键的键盘按下事件 - DispatchQueue.main.asyncAfter(deadline: .now() + delay) { - self.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 - } + CommandManager.shared.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings!) } } diff --git a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m index b6793bc4..ec461cde 100644 --- a/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m +++ b/Limelight/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m @@ -35,7 +35,7 @@ - (void) viewWillDisappear:(BOOL)animated{ - OnScreenKeyView.editMode = false; + OnScreenKeyboardButtonView.editMode = false; [super viewWillDisappear:animated]; [[NSNotificationCenter defaultCenter] postNotificationName:@"OscLayoutCloseNotification" object:self]; } @@ -48,7 +48,7 @@ for (UIView *subview in self.view.subviews) { // 检查子视图是否是特定类型的实例 - if ([subview isKindOfClass:[OnScreenKeyView class]]) { + if ([subview isKindOfClass:[OnScreenKeyboardButtonView class]]) { // 如果是,就添加到将要被移除的数组中 [subview removeFromSuperview]; } @@ -63,7 +63,7 @@ for (NSData *buttonStateEncoded in oscProfile.buttonStates) { OnScreenButtonState* buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil]; if(buttonState.buttonType == KeyboardButton){ - OnScreenKeyView* keyView = [[OnScreenKeyView alloc] initWithKeyString:buttonState.name keyLabel:buttonState.alias]; //reconstruct keyView + OnScreenKeyboardButtonView* keyView = [[OnScreenKeyboardButtonView alloc] initWithKeyString:buttonState.name keyLabel:buttonState.alias]; //reconstruct keyView keyView.translatesAutoresizingMaskIntoConstraints = NO; // weird but this is mandatory, or you will find no key views added to the right place keyView.timestamp = buttonState.timestamp; // will be set as key in in the dict. // Add the KeyView to the view controller's view @@ -165,7 +165,7 @@ - (void) viewDidAppear:(BOOL)animated { - OnScreenKeyView.editMode = true; + OnScreenKeyboardButtonView.editMode = true; [super viewWillAppear:animated]; [self profileRefresh]; } @@ -282,14 +282,58 @@ } - (IBAction) addTapped:(id)sender{ - OnScreenKeyView* keyView = [[OnScreenKeyView alloc] initWithKeyString:@"ALT" keyLabel:@"test"]; - keyView.translatesAutoresizingMaskIntoConstraints = NO; // weird but this is mandatory, or you will find no key views added to the right place - keyView.timestamp = CACurrentMediaTime(); // will be set as key in in the dict. - [self.onScreenKeyViewsDict setObject:keyView forKey:@(keyView.timestamp)]; - // Add the KeyView to the view controller's view - [self.view addSubview:keyView]; - [keyView setKeyLocationWithXOffset:50 yOffset:50]; + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[LocalizationHelper localizedStringForKey:@"New Keyboard Button"] + message:[LocalizationHelper localizedStringForKey:@"Enter the command & key label"] + preferredStyle:UIAlertControllerStyleAlert]; + + [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.placeholder = [LocalizationHelper localizedStringForKey:@"Command"]; + textField.keyboardType = UIKeyboardTypeASCIICapable; + textField.autocorrectionType = UITextAutocorrectionTypeNo; + textField.spellCheckingType = UITextSpellCheckingTypeNo; + }]; + + [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { + textField.placeholder = [LocalizationHelper localizedStringForKey:@"Key label (optional)"]; + textField.keyboardType = UIKeyboardTypeASCIICapable; + textField.autocorrectionType = UITextAutocorrectionTypeNo; + textField.spellCheckingType = UITextSpellCheckingTypeNo; + }]; + + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Cancel"] + style:UIAlertActionStyleCancel + handler:nil]; + + UIAlertAction *okAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"OK"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action) { + /* + alertController.textFields[0].keyboardType = UIKeyboardTypeASCIICapable; + alertController.textFields[0].autocorrectionType = UITextAutocorrectionTypeNo; + alertController.textFields[0].spellCheckingType = UITextSpellCheckingTypeNo; + alertController.textFields[1].keyboardType = UIKeyboardTypeASCIICapable; + alertController.textFields[1].autocorrectionType = UITextAutocorrectionTypeNo; + alertController.textFields[1].spellCheckingType = UITextSpellCheckingTypeNo;*/ + + NSString *keyboardCmdString = [alertController.textFields[0].text uppercaseString]; // convert to uppercase + NSString *keyLabel = alertController.textFields[1].text; + if([keyLabel isEqualToString:@""]) keyLabel = [[keyboardCmdString lowercaseString] capitalizedString]; + if([CommandManager.shared extractKeyStringsFrom:keyboardCmdString] == nil) return; // this is a invalid string. + + //saving & present the keyboard button: + OnScreenKeyboardButtonView* keyView = [[OnScreenKeyboardButtonView alloc] initWithKeyString:keyboardCmdString keyLabel:keyLabel]; + keyView.translatesAutoresizingMaskIntoConstraints = NO; // weird but this is mandatory, or you will find no key views added to the right place + keyView.timestamp = CACurrentMediaTime(); // will be set as key in in the dict. + [self.onScreenKeyViewsDict setObject:keyView forKey:@(keyView.timestamp)]; + // Add the KeyView to the view controller's view + [self.view addSubview:keyView]; + [keyView setKeyLocationWithXOffset:50 yOffset:50]; + }]; + [alertController addAction:cancelAction]; + [alertController addAction:okAction]; + [self presentViewController:alertController animated:YES completion:nil]; } @@ -310,36 +354,6 @@ }]]; [self presentViewController:savedAlertController animated:YES completion:nil]; } - - /* - if ([self->profilesManager profileNameAlreadyExist:enteredProfileName] == YES) { // if the entered profile name already exists then let the user know. Offer to allow them to overwrite the existing profile - UIAlertController * savedAlertController = [UIAlertController alertControllerWithTitle: [NSString stringWithFormat:@""] message: [NSString stringWithFormat:@"Another profile with the name '%@' already exists! Do you want to overwrite it?", enteredProfileName] preferredStyle:UIAlertControllerStyleAlert]; - - [savedAlertController addAction:[UIAlertAction actionWithTitle:@"Yes" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // overwrite existing profile - [self->profilesManager saveProfileWithName: enteredProfileName andButtonLayers:self.layoutOSC.OSCButtonLayers]; - }]]; - - [savedAlertController addAction:[UIAlertAction actionWithpinNo" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // don't overwrite the existing profile - [savedAlertController dismissViewControllerAnimated:NO completion:nil]; - }]]; - [self presentViewController:savedAlertController animated:YES completion:nil]; - } - else { // if user entered a valid name that doesn't already exist then save the profile to persistent storage - [self->profilesManager saveProfileWithName: enteredProfileName andButtonLayers:self.layoutOSC.OSCButtonLayers]; - [self->profilesManager setProfileToSelected: enteredProfileName]; - - UIAlertController * savedAlertController = [UIAlertController alertControllerWithTitle: [NSString stringWithFormat:@""] message: [NSString stringWithFormat:@"%@ profile saved and set as your active in-game controller profile layout", enteredProfileName] preferredStyle:UIAlertControllerStyleAlert]; // Let user know this profile has been saved and is now the selected controller layout - - [savedAlertController addAction:[UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - [savedAlertController dismissViewControllerAnimated:NO completion:nil]; - }]]; - [self presentViewController:savedAlertController animated:YES completion:nil]; - } - }]]; - [inputNameAlertController addAction:[UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Cancel"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { // adds a button that allows user to decline the option to save the controller layout they currently see on screen - [inputNameAlertController dismissViewControllerAnimated:NO completion:nil]; - }]]; - [self presentViewController:inputNameAlertController animated:YES completion:nil]; */ } @@ -471,9 +485,9 @@ // removing keyboard buttons objs UITouch *touch = [touches anyObject]; // Get the first touch in the set if([self touchWithinTashcanButton:touch]){ - [self.onScreenKeyViewsDict[@(OnScreenKeyView.timestampOfButtonBeingDragged)] removeFromSuperview]; - [self.onScreenKeyViewsDict removeObjectForKey:@(OnScreenKeyView.timestampOfButtonBeingDragged)]; - OnScreenKeyView.timestampOfButtonBeingDragged = 0; //reset thie timestamp + [self.onScreenKeyViewsDict[@(OnScreenKeyboardButtonView.timestampOfButtonBeingDragged)] removeFromSuperview]; + [self.onScreenKeyViewsDict removeObjectForKey:@(OnScreenKeyboardButtonView.timestampOfButtonBeingDragged)]; + OnScreenKeyboardButtonView.timestampOfButtonBeingDragged = 0; //reset thie timestamp } diff --git a/Limelight/ViewControllers/OnScreenKeyManagerViewController.swift b/Limelight/ViewControllers/OnScreenKeyManagerViewController.swift deleted file mode 100644 index 2b0b38e0..00000000 --- a/Limelight/ViewControllers/OnScreenKeyManagerViewController.swift +++ /dev/null @@ -1,339 +0,0 @@ -// -// KeyManagerViewController.swift -// Moonlight-ZWM -// -// Created by ZWM on 2024/7/23. -// Copyright © 2024 Moonlight Game Streaming Project. All rights reserved. -// - -import UIKit - -@objc public class OnScreenKeyManagerViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { - - public let tableView = UITableView() - private let addButton = UIButton(type: .system) - private let deleteButton = UIButton(type: .system) - private let editButton = UIButton(type: .system) - private let exitButton = UIButton(type: .system) - private let pinButton = UIButton(type: .system) - private let viewBackgroundColor = UIColor(white: 0.2, alpha: 0.8); - private let highlightColor = UIColor(white: 0.39, alpha: 0.8); - private let titleLabel = UILabel() - - private var viewPinned: Bool = false - private var isEditingMode: Bool = false { - didSet { - updateEditingMode() - } - } - - override public func viewDidLoad() { - super.viewDidLoad() - - setupViews() - updateEditingMode() - - tableView.dataSource = self - tableView.delegate = self - - // Register the cell class - tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") - //pass self to the CommandManager - //CommandManager.shared.viewController = self - } - - override public func viewDidLayoutSubviews() { - super.viewDidLayoutSubviews() - setupConstraints() - } - - private func setupViews() { - - // Set corner radius - view.layer.cornerRadius = 20 // Adjust the corner radius - view.layer.masksToBounds = true - - // Set up the title label - titleLabel.text = SwiftLocalizationHelper.localizedString(forKey: "Send Commands") - titleLabel.font = UIFont.boldSystemFont(ofSize: 20) // Adjust font size as needed - titleLabel.textColor = UIColor.white // Adjust color as needed - titleLabel.textAlignment = .center - view.addSubview(titleLabel) - - view.backgroundColor = viewBackgroundColor - tableView.backgroundColor = .clear - tableView.rowHeight = 60 - tableView.separatorColor = highlightColor - // Configure buttons - addButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Add / Duplicate"), for: .normal) - deleteButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Delete"), for: .normal) - editButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Edit"), for: .normal) - exitButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Exit"), for: .normal) - pinButton.setTitle("📌", for: .normal) - addButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) // Adjust the size as needed - deleteButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) - editButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) - exitButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) - pinButton.titleLabel?.font = UIFont.systemFont(ofSize: 20) - - // Add subviews - view.addSubview(tableView) - view.addSubview(addButton) - view.addSubview(deleteButton) - view.addSubview(editButton) - view.addSubview(exitButton) - view.addSubview(pinButton) - - // Setup button targets - addButton.addTarget(self, action: #selector(addButtonTapped), for: .touchUpInside) - deleteButton.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside) - editButton.addTarget(self, action: #selector(editButtonTapped), for: .touchUpInside) - exitButton.addTarget(self, action: #selector(exitButtonTapped), for: .touchUpInside) - pinButton.addTarget(self, action: #selector(pinButtonTapped), for: .touchUpInside) - pinButton.contentEdgeInsets = UIEdgeInsets(top: 7, left: 20, bottom: 7, right: 20) - - } - - private func setupConstraints() { - - guard let superview = view.superview else { - return - } - - view.translatesAutoresizingMaskIntoConstraints = false - - tableView.translatesAutoresizingMaskIntoConstraints = false - addButton.translatesAutoresizingMaskIntoConstraints = false - deleteButton.translatesAutoresizingMaskIntoConstraints = false - editButton.translatesAutoresizingMaskIntoConstraints = false - exitButton.translatesAutoresizingMaskIntoConstraints = false - pinButton.translatesAutoresizingMaskIntoConstraints = false - titleLabel.translatesAutoresizingMaskIntoConstraints = false - - NSLayoutConstraint.activate([ - - // Set the width and height of the view - view.widthAnchor.constraint(equalTo: view.superview!.widthAnchor, multiplier: 1), - view.heightAnchor.constraint(equalTo: view.superview!.heightAnchor, multiplier: 1), - - // Center the view horizontally and vertically - view.centerXAnchor.constraint(equalTo: view.superview!.centerXAnchor), - view.centerYAnchor.constraint(equalTo: view.superview!.centerYAnchor), - - // ViewTitle constrains - titleLabel.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 13.5), - titleLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10), - titleLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10), - - - // TableView constraints - tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 10), - tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -10), - tableView.topAnchor.constraint(equalTo: view.topAnchor, constant: 50), - tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -60), - - // ExitButton constraints - exitButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 25), - exitButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10), - - // EditButton constraints - editButton.leadingAnchor.constraint(equalTo: exitButton.trailingAnchor, constant: 50), - editButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10), - - // AddButton constraints - addButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -25), - addButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10), - - // DeleteButton constraints - deleteButton.trailingAnchor.constraint(equalTo: addButton.leadingAnchor, constant: -50), - deleteButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10), - - // DeleteButton constraints - pinButton.trailingAnchor.constraint(equalTo: deleteButton.leadingAnchor, constant: -50), - pinButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -10), - ]) - } - - // view controller method - private func updateEditingMode() { - addButton.isEnabled = isEditingMode - deleteButton.isEnabled = isEditingMode - if(isEditingMode){ editButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Done"), for: .normal) } - else{ editButton.setTitle(SwiftLocalizationHelper.localizedString(forKey: "Edit"), for: .normal) } - } - - // view controller method - @objc private func pinButtonTapped() { - viewPinned = !viewPinned - if viewPinned { - pinButton.backgroundColor = highlightColor - } - else{ - pinButton.backgroundColor = viewBackgroundColor - } - } - - // tobe modified - @objc private func addButtonTapped() { - let previouslySelectedIndexPath = tableView.indexPathForSelectedRow //memorize selected indexpath - let alert = UIAlertController(title: SwiftLocalizationHelper.localizedString(forKey: "New Command"), message: SwiftLocalizationHelper.localizedString(forKey: "Enter a new command and alias"), preferredStyle: .alert) - alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey:"Command") } - alert.addTextField { $0.placeholder = SwiftLocalizationHelper.localizedString(forKey: "Alias (optional)") } - alert.textFields?[0].keyboardType = .asciiCapable - alert.textFields?[0].autocorrectionType = .no - alert.textFields?[0].spellCheckingType = .no - alert.textFields?[1].keyboardType = .asciiCapable - alert.textFields?[1].autocorrectionType = .no - alert.textFields?[1].spellCheckingType = .no - - let submitAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey: "Add"), style: .default) { [unowned alert] _ in - let keyboardCmdString = alert.textFields?[0].text ?? "" - let alias = alert.textFields?[1].text ?? keyboardCmdString - let newCommand = RemoteCommand(keyboardCmdString: keyboardCmdString, alias: alias) - let addCommandSuceeded = CommandManager.shared.addCommand(newCommand) - //self.reloadTableView() // don't know why but this reload has to be called from the CommandManager, it doesn't work here. - - //if previouslySelectedIndexPath == nil { return } - if addCommandSuceeded { - let lastRow = self.tableView.numberOfRows(inSection: 0) - 1 //for now there's only 1 section for the tableview, just use setion 0 - let newEntryIndexPath = IndexPath(row: lastRow, section: 0) - self.tableView.selectRow(at: newEntryIndexPath, animated: true, scrollPosition: .middle) // shift the highlight to the newly added entry - } - else { - self.tableView.selectRow(at: previouslySelectedIndexPath, animated: true, scrollPosition: .middle) // keep the highlight on the previous entry if failed to add command - } - } - - let cancelAction = UIAlertAction(title: SwiftLocalizationHelper.localizedString(forKey:"Cancel"), style: .cancel) - alert.addAction(submitAction) - alert.addAction(cancelAction) - - if let selectedIndexPath = self.tableView.indexPathForSelectedRow { - let selectedCommand = CommandManager.shared.getAllCommands()[selectedIndexPath.row] - alert.textFields?[0].text = selectedCommand.keyboardCmdString // load selected keyboard cmd string - //alert.textFields?[1].text = selectedCommand.alias // leave the alias input field empty - } - - self.present(alert, animated: true) - } - - // tobe modified - @objc private func deleteButtonTapped() { - guard let selectedIndexPath = tableView.indexPathForSelectedRow else { - return - } - let previouslySelectedIndexPath = selectedIndexPath // memorize selected row before reloading tableview - - CommandManager.shared.deleteCommand(at: selectedIndexPath.row) - reloadTableView() - // target new entry after deletion - var targetRowAfterDel = previouslySelectedIndexPath.row - 1 - if targetRowAfterDel < 0 { targetRowAfterDel = 0 } - let targetIndexPathAfterDel = IndexPath(row: targetRowAfterDel, section: previouslySelectedIndexPath.section) - if targetRowAfterDel < tableView.numberOfRows(inSection: previouslySelectedIndexPath.section) { - tableView.selectRow(at: targetIndexPathAfterDel, animated: true, scrollPosition: .middle) // shift highlight to the target entry after deletion - } - } - - @objc private func editButtonTapped() { - isEditingMode.toggle() - } - - @objc private func exitButtonTapped() { - dismiss(animated: true, completion: nil) - } - - @objc public func reloadTableView() { - tableView.layoutIfNeeded() - tableView.reloadData() - - /* - let previouslySelectedIndexPath = tableView.indexPathForSelectedRow - if let indexPath = previouslySelectedIndexPath { - // Make sure the indexPath is still valid and scroll to the selected indexPath - if indexPath.row < tableView.numberOfRows(inSection: indexPath.section) { - tableView.selectRow(at: indexPath, animated: true, scrollPosition: .middle) // keep the entry of previous index selected. - } - } */ - } - - // tobe modified - // UITableViewDataSource - public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return CommandManager.shared.getAllCommands().count - } - - - // tobe modified - public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) - // Configure cell appearance - cell.backgroundColor = .clear // Set background color of the cell - cell.textLabel?.textColor = UIColor.white // Set font color of the text - - - // Set selected background view - let selectedBackgroundView = UIView() - selectedBackgroundView.backgroundColor = highlightColor // Color for the selected state - cell.selectedBackgroundView = selectedBackgroundView - - let command = CommandManager.shared.getAllCommands()[indexPath.row] - cell.textLabel?.text = command.alias - return cell - } - - - // UITableViewDelegate - // tobe modified - public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - - if let cell = tableView.cellForRow(at: indexPath) { - // Set the cell background color to the flashing color - // Animate the flash effect - UIView.animate(withDuration: 0.1, animations: { - cell.selectedBackgroundView?.backgroundColor = .clear - }) { _ in - // Reset the cell background color after the animation - UIView.animate(withDuration: 0.1) { - cell.selectedBackgroundView?.backgroundColor = self.highlightColor - } - } - } - - if !isEditingMode { - // Sending keyboard command - let command = CommandManager.shared.getAllCommands()[indexPath.row] - sendKeyboardCommand(command) - if !viewPinned { dismiss(animated: false, completion: nil) } // dimiss the view in sending mode & the view is not pinned - } - } - - private func sendKeyboardCommand(_ cmd: RemoteCommand) { - print("Sending key-value") - let keyboardCmdStrings = CommandManager.shared.extractKeyStrings(from: cmd.keyboardCmdString) - sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings!) - } - - private func sendKeyDownEventWithDelay(keyboardCmdStrings: [String], delay: TimeInterval = 0.05, index: Int = 0) { - guard index < keyboardCmdStrings.count else { - for keyStr in keyboardCmdStrings { - LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_UP), 0) - } - return - } // 如果已经处理完所有键,释放所有按键 - - let keyCode = CommandManager.keyMappings[keyboardCmdStrings[index]] - guard let keyCode = keyCode else { - print("No mapping found for \(keyboardCmdStrings[index])") - sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 - return - } - // 发送当前键的键盘按下事件 - LiSendKeyboardEvent(keyCode,Int8(KEY_ACTION_DOWN), 0) - // 使用 asyncAfter 在指定异步延迟后发送下一个键的键盘按下事件 - DispatchQueue.main.asyncAfter(deadline: .now() + delay) { - self.sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个 - } - } -} - diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index e1c635c8..ff1203f2 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -16,6 +16,7 @@ #import "CustomTapGestureRecognizer.h" #import "LocalizationHelper.h" #import "Moonlight-Swift.h" +#import "OSCProfilesManager.h" #include #include @@ -155,7 +156,7 @@ [_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig]; //reinitiate setupStreamView process. [self->_streamView reloadOnScreenControlsRealtimeWith:(ControllerSupport*)_controllerSupport andConfig:(StreamConfiguration*)_streamConfig]; //reload OSC here. - + [self->_streamView reloadOnScreenKeyboardButtons]; //reload keyboard buttons here. the keyboard button view will be added to the streamframe view instead streamview, the highest layer, which saves a lot of reengineering //reconfig statsOverlay self->_statsUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self @@ -169,10 +170,12 @@ + - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - + //[self layoutOnScreenKeyboardButtons]; + // onscreen keyView test /* @@ -188,9 +191,9 @@ CGFloat yOffset = 550; CGFloat spacing = 10.0; - [keyView setKeyLocationWithXOffset:500 yOffset:(CGFloat)550]; + [keyView setKeyLocationWithXOffset:500 yOffset:(CGFloat)550]; */ - */ + @@ -346,6 +349,7 @@ - (void)layoutOSC{ [self->_streamView disableOnScreenControls]; + [self->_streamView clearOnScreenKeyboardButtons]; // clear all onScreenKeyboardButtons before entering edit mode [self presentViewController:_layoutOnScreenControlsVC animated:YES completion:nil]; } @@ -355,6 +359,7 @@ [self->_streamView reloadOnScreenControlsWith:(ControllerSupport*)_controllerSupport andConfig:(StreamConfiguration*)_streamConfig]; [self->_streamView showOnScreenControls]; + [self->_streamView reloadOnScreenKeyboardButtons]; //update keyboard buttons here } diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 01879216..3c904319 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 840751B32BF49C050096B657 /* CustomTapGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 840751B22BF49C050096B657 /* CustomTapGestureRecognizer.m */; }; - 84203F232C5F24C00032EEED /* OnScreenKeyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84203F222C5F24C00032EEED /* OnScreenKeyView.swift */; }; + 84203F232C5F24C00032EEED /* OnScreenKeyboardButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84203F222C5F24C00032EEED /* OnScreenKeyboardButtonView.swift */; }; 84351B0E2C29ACCB00A77989 /* LayoutOnScreenControls.m in Sources */ = {isa = PBXBuildFile; fileRef = 84351B072C29ACCA00A77989 /* LayoutOnScreenControls.m */; }; 84351B0F2C29ACCB00A77989 /* OnScreenButtonState.m in Sources */ = {isa = PBXBuildFile; fileRef = 84351B092C29ACCA00A77989 /* OnScreenButtonState.m */; }; 84351B102C29ACCB00A77989 /* OSCProfile.m in Sources */ = {isa = PBXBuildFile; fileRef = 84351B0A2C29ACCA00A77989 /* OSCProfile.m */; }; @@ -24,7 +24,6 @@ 8454AC662C31907F00F0A302 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8454AC682C31907F00F0A302 /* iPad.storyboard */; }; 8454AC6A2C319BDA00F0A302 /* iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8454AC6C2C319BDA00F0A302 /* iPhone.storyboard */; }; 84591A512BE1625E006AAB10 /* CustomEdgeSwipeGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84591A502BE1625E006AAB10 /* CustomEdgeSwipeGestureRecognizer.m */; }; - 84866ACC2C63A6340037EB63 /* OnScreenKeyManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84866ACB2C63A6340037EB63 /* OnScreenKeyManagerViewController.swift */; }; 84E1CDEC2C4F67D300547904 /* CommandManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1CDEB2C4F67D300547904 /* CommandManager.swift */; }; 84E1CDEF2C4F688E00547904 /* CommandManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1CDEE2C4F688E00547904 /* CommandManagerViewController.swift */; }; 84E1CDFA2C4FE83400547904 /* SwiftLocalizationHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1CDF92C4FE83400547904 /* SwiftLocalizationHelper.swift */; }; @@ -127,7 +126,7 @@ 693B3A9A218638CD00982F7B /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = ""; }; 840751B12BF49B5A0096B657 /* CustomTapGestureRecognizer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CustomTapGestureRecognizer.h; sourceTree = ""; }; 840751B22BF49C050096B657 /* CustomTapGestureRecognizer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CustomTapGestureRecognizer.m; sourceTree = ""; }; - 84203F222C5F24C00032EEED /* OnScreenKeyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnScreenKeyView.swift; sourceTree = ""; }; + 84203F222C5F24C00032EEED /* OnScreenKeyboardButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnScreenKeyboardButtonView.swift; sourceTree = ""; }; 84351B062C29ACCA00A77989 /* OnScreenButtonState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OnScreenButtonState.h; sourceTree = ""; }; 84351B072C29ACCA00A77989 /* LayoutOnScreenControls.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LayoutOnScreenControls.m; sourceTree = ""; }; 84351B082C29ACCA00A77989 /* OSCProfilesManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSCProfilesManager.h; sourceTree = ""; }; @@ -156,7 +155,6 @@ 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 = ""; }; - 84866ACB2C63A6340037EB63 /* OnScreenKeyManagerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnScreenKeyManagerViewController.swift; 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 = ""; }; @@ -627,7 +625,7 @@ 988FCD3F293B091B003050E2 /* KeyboardInputField.h */, 988FCD40293B091B003050E2 /* KeyboardInputField.m */, 84E1CDEB2C4F67D300547904 /* CommandManager.swift */, - 84203F222C5F24C00032EEED /* OnScreenKeyView.swift */, + 84203F222C5F24C00032EEED /* OnScreenKeyboardButtonView.swift */, ); path = Input; sourceTree = ""; @@ -692,7 +690,6 @@ FB4A23B61A9D3637004D2EF2 /* LoadingFrameViewController.h */, FB4A23B71A9D3637004D2EF2 /* LoadingFrameViewController.m */, 84E1CDEE2C4F688E00547904 /* CommandManagerViewController.swift */, - 84866ACB2C63A6340037EB63 /* OnScreenKeyManagerViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -1023,7 +1020,6 @@ FBDE86E619F82297001C18A8 /* UIAppView.m in Sources */, FB89462F19F646E200339C8A /* Connection.m in Sources */, FB9AFD321A7D867C00872C98 /* AppAssetRetriever.m in Sources */, - 84866ACC2C63A6340037EB63 /* OnScreenKeyManagerViewController.swift in Sources */, 843E93BE2C41528700B1651F /* OrientationHelper.swift in Sources */, FB4678FF1A565DAC00377732 /* WakeOnLanManager.m in Sources */, 84E1CDEC2C4F67D300547904 /* CommandManager.swift in Sources */, @@ -1035,7 +1031,7 @@ FBDE86E019F7A837001C18A8 /* UIComputerView.m in Sources */, FB89463019F646E200339C8A /* StreamConfiguration.m in Sources */, FBD3495319FF36FB002D2A60 /* SWRevealViewController.m in Sources */, - 84203F232C5F24C00032EEED /* OnScreenKeyView.swift in Sources */, + 84203F232C5F24C00032EEED /* OnScreenKeyboardButtonView.swift in Sources */, 84FD0B512C31338D006B5BE5 /* LocalizationHelper.m in Sources */, FB1D59971BBCCB6400F482CA /* ComputerScrollView.m in Sources */, FBD3495019FF2174002D2A60 /* SettingsViewController.m in Sources */,