Merge branch 'newTouchPad' into noWaterMark
This commit is contained in:
@@ -57,7 +57,9 @@ import UIKit
|
||||
"M_X1" : BUTTON_X1,
|
||||
"M_X2" : BUTTON_X2]
|
||||
|
||||
static let keyMappings: [String: Int16] = [
|
||||
@objc public static let touchPadCmds: [String] = ["LS_PAD", "RS_PAD", "M_PAD"]
|
||||
|
||||
static let keyboardButtonMappings: [String: Int16] = [
|
||||
// Windows Key Codes
|
||||
"CTRL": 0x11, // VK_CONTROL
|
||||
"SHIFT": 0x10, // VK_SHIFT
|
||||
@@ -263,12 +265,12 @@ import UIKit
|
||||
}
|
||||
|
||||
@objc public func createTestKeyMappings() -> [String: Int16] {
|
||||
return CommandManager.keyMappings
|
||||
return CommandManager.keyboardButtonMappings
|
||||
}
|
||||
|
||||
// extractKeyStrings from keyboardCMDString
|
||||
@objc public func extractKeyStrings(from input: String) -> [String]? {
|
||||
let keys = CommandManager.keyMappings.keys.joined(separator: "|")
|
||||
let keys = CommandManager.keyboardButtonMappings.keys.joined(separator: "|")
|
||||
let pattern = "^(?:(\(keys))(?:\\+(\(keys))*)*)$"
|
||||
|
||||
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else {
|
||||
@@ -293,7 +295,7 @@ import UIKit
|
||||
var validKeyStrings: [String] = []
|
||||
|
||||
for key in keyStrings {
|
||||
if CommandManager.keyMappings.keys.contains(key) {
|
||||
if CommandManager.keyboardButtonMappings.keys.contains(key) {
|
||||
validKeyStrings.append(key)
|
||||
} else {
|
||||
print(" '\(key)' is not defined in key mappings")
|
||||
@@ -366,12 +368,12 @@ import UIKit
|
||||
@objc public func sendKeyDownEventWithDelay(keyboardCmdStrings: [String], delay: TimeInterval = 0.2, index: Int = 0) { // we need a large delay for WAN streaming
|
||||
guard index < keyboardCmdStrings.count else {
|
||||
for keyStr in keyboardCmdStrings {
|
||||
LiSendKeyboardEvent(CommandManager.keyMappings[keyStr]!,Int8(KEY_ACTION_UP), 0)
|
||||
LiSendKeyboardEvent(CommandManager.keyboardButtonMappings[keyStr]!,Int8(KEY_ACTION_UP), 0)
|
||||
}
|
||||
return
|
||||
} // 如果已经处理完所有键,释放所有按键
|
||||
|
||||
let keyCode = CommandManager.keyMappings[keyboardCmdStrings[index]]
|
||||
let keyCode = CommandManager.keyboardButtonMappings[keyboardCmdStrings[index]]
|
||||
guard let keyCode = keyCode else {
|
||||
print("No mapping found for \(keyboardCmdStrings[index])")
|
||||
sendKeyDownEventWithDelay(keyboardCmdStrings: keyboardCmdStrings, delay: delay, index: index+1) // 跳过当前键,继续下一个
|
||||
|
||||
@@ -90,7 +90,13 @@ import UIKit
|
||||
defaultBorderColor = UIColor(white: 0.2, alpha: borderAlpha).cgColor
|
||||
self.layer.borderColor = defaultBorderColor
|
||||
|
||||
self.backgroundColor = UIColor(white: 0.2, alpha: self.backgroundAlpha - 0.18) // offset to be consistent with onScreen controller layer opacity
|
||||
if CommandManager.touchPadCmds.contains(self.keyString){
|
||||
self.backgroundColor = UIColor.clear // make touchPad transparent
|
||||
self.layer.borderColor = UIColor(white: 0.2, alpha: borderAlpha - 0.2).cgColor // reduce border alpha for touchPad
|
||||
}
|
||||
else{ // backgroundColor works for buttons other than touch pad
|
||||
self.backgroundColor = UIColor(white: 0.2, alpha: self.backgroundAlpha - 0.18) // offset to be consistent with onScreen controller layer opacity
|
||||
}
|
||||
}
|
||||
|
||||
@objc public func resizeButtonView(){
|
||||
@@ -152,7 +158,15 @@ import UIKit
|
||||
self.borderLayer.borderColor = defaultBorderColor
|
||||
|
||||
self.layer.cornerRadius = 15
|
||||
self.backgroundColor = UIColor(white: 0.2, alpha: self.backgroundAlpha - 0.18) // offset to be consistent with OSC opacity
|
||||
|
||||
if CommandManager.touchPadCmds.contains(self.keyString){
|
||||
self.backgroundColor = UIColor.clear // make touchPad transparent
|
||||
self.layer.borderColor = UIColor(white: 0.2, alpha: borderAlpha - 0.2).cgColor // reduce border alpha for touchPad
|
||||
label.text = "" // make touchPad display no text
|
||||
}
|
||||
else{ // backgroundColor works for buttons other than touch pad
|
||||
self.backgroundColor = UIColor(white: 0.2, alpha: self.backgroundAlpha - 0.18) // offset to be consistent with onScreen controller layer opacity
|
||||
}
|
||||
// self.layer.shadowColor = UIColor.clear.cgColor
|
||||
// self.layer.shadowRadius = 8
|
||||
// self.layer.shadowOpacity = 0.5
|
||||
@@ -237,7 +251,9 @@ import UIKit
|
||||
|
||||
if !OnScreenButtonView.editMode {
|
||||
// self.backgroundColor = UIColor.systemBlue.withAlphaComponent(0.7)
|
||||
self.buttonDownVisualEffect()
|
||||
if !CommandManager.touchPadCmds.contains(self.keyString) {
|
||||
self.buttonDownVisualEffect()
|
||||
}
|
||||
// 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)!
|
||||
@@ -247,13 +263,11 @@ import UIKit
|
||||
}
|
||||
}
|
||||
// if there's no "+" in the keystring, treat it as a regular button:
|
||||
else{
|
||||
if(CommandManager.mouseButtonMappings.keys.contains(self.keyString)){
|
||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), Int32(CommandManager.mouseButtonMappings[self.keyString]!))
|
||||
}
|
||||
else{
|
||||
LiSendKeyboardEvent(CommandManager.keyMappings[self.keyString]!,Int8(KEY_ACTION_DOWN), 0)
|
||||
}
|
||||
if CommandManager.keyboardButtonMappings.keys.contains(self.keyString) {
|
||||
LiSendKeyboardEvent(CommandManager.keyboardButtonMappings[self.keyString]!,Int8(KEY_ACTION_DOWN), 0)
|
||||
}
|
||||
if CommandManager.mouseButtonMappings.keys.contains(self.keyString) {
|
||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), Int32(CommandManager.mouseButtonMappings[self.keyString]!))
|
||||
}
|
||||
}
|
||||
// here is in edit mode:
|
||||
@@ -283,31 +297,43 @@ import UIKit
|
||||
storedLocation = currentLocation // Update initial center for next movement
|
||||
}
|
||||
}
|
||||
else{
|
||||
if touches.count == 1 && false{
|
||||
let currentLocation: CGPoint = (touches.first?.location(in: self))!
|
||||
deltaX = currentLocation.x - self.latestMousePointerLocation.x
|
||||
deltaY = currentLocation.y - self.latestMousePointerLocation.y
|
||||
// NSLog("coord test deltaX: %f, deltaY: %f", deltaX, deltaY)
|
||||
self.onScreenControls.sendLeftStickTouchPadEvent(withDeltaX: deltaX, deltaY: deltaY);
|
||||
}
|
||||
else if true{
|
||||
handleTouchPadEvent(touches: touches)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleTouchPadEvent (touches: Set<UITouch>){
|
||||
if touches.count == 1{
|
||||
let currentLocation: CGPoint = (touches.first?.location(in: self))!
|
||||
deltaX = currentLocation.x - self.latestMousePointerLocation.x
|
||||
deltaY = currentLocation.y - self.latestMousePointerLocation.y
|
||||
if self.keyString == "LS_PAD" {
|
||||
// NSLog("coord test deltaX: %f, deltaY: %f", deltaX, deltaY)
|
||||
// latestMousePointerLocation = currentLocation
|
||||
self.onScreenControls.sendLeftStickTouchPadEvent(withDeltaX: deltaX, deltaY: deltaY);
|
||||
}
|
||||
if self.keyString == "RS_PAD" {
|
||||
// NSLog("coord test deltaX: %f, deltaY: %f", deltaX, deltaY)
|
||||
// latestMousePointerLocation = currentLocation
|
||||
self.onScreenControls.sendRightStickTouchPadEvent(withDeltaX: deltaX, deltaY: deltaY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
// self.pressed = false // will be reset outside the class
|
||||
super.touchesEnded(touches, with: event)
|
||||
if !OnScreenButtonView.editMode && touches.count == 1 {
|
||||
self.onScreenControls.clearLeftStickTouchPadFlag();
|
||||
self.onScreenControls.clearLeftStickTouchPadFlag()
|
||||
self.onScreenControls.clearRightStickTouchPadFlag()
|
||||
}
|
||||
if !OnScreenButtonView.editMode && !self.keyString.contains("+") { // if the command(keystring contains "+", it's a multi-key command rather than a single key button
|
||||
|
||||
if(CommandManager.mouseButtonMappings.keys.contains(self.keyString)){
|
||||
if CommandManager.mouseButtonMappings.keys.contains(self.keyString){
|
||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_RELEASE), Int32(CommandManager.mouseButtonMappings[self.keyString]!))
|
||||
}
|
||||
else{
|
||||
LiSendKeyboardEvent(CommandManager.keyMappings[self.keyString]!,Int8(KEY_ACTION_UP), 0)
|
||||
if CommandManager.keyboardButtonMappings.keys.contains(self.keyString) {
|
||||
LiSendKeyboardEvent(CommandManager.keyboardButtonMappings[self.keyString]!,Int8(KEY_ACTION_UP), 0)
|
||||
}
|
||||
self.buttonUpVisualEffect()
|
||||
return;
|
||||
|
||||
@@ -147,33 +147,34 @@ static float L3_Y;
|
||||
}
|
||||
|
||||
- (void) sendRightStickTouchPadEventWithDeltaX:(CGFloat) deltaX deltaY: (CGFloat) deltaY{
|
||||
CGFloat controllerX = 0x7FFE * deltaX / 50;
|
||||
CGFloat controllerX = 0x7FFE * deltaX / 30;
|
||||
if(controllerX > 0x7FFE) controllerX = 0x7FFE;
|
||||
if(controllerX < -0x7FFE) controllerX = -0x7FFE;
|
||||
CGFloat controllerY = 0x7FFE * deltaY / 50;
|
||||
CGFloat controllerY = 0x7FFE * deltaY / 30;
|
||||
if(controllerY > 0x7FFE) controllerY = 0x7FFE;
|
||||
if(controllerY < -0x7FFE) controllerY = -0x7FFE;
|
||||
[_controllerSupport updateRightStick:_controller x: controllerX y: - controllerY]; // stick value populated to the controllerSupport here
|
||||
[_controllerSupport updateFinished:_controller];
|
||||
}
|
||||
|
||||
- (void) clearRightStickTouchPadFlag{
|
||||
[_controllerSupport updateRightStick:_controller x:0 y:0];
|
||||
[_controllerSupport clearButtonFlag:_controller flags:RS_CLK_FLAG];
|
||||
[_controllerSupport updateFinished:_controller];
|
||||
}
|
||||
|
||||
- (void) sendLeftStickTouchPadEventWithDeltaX:(CGFloat) deltaX deltaY: (CGFloat) deltaY{
|
||||
CGFloat controllerX = 0x7FFE * deltaX / 50;
|
||||
CGFloat controllerX = 0x7FFE * deltaX / 35;
|
||||
if(controllerX > 0x7FFE) controllerX = 0x7FFE;
|
||||
if(controllerX < -0x7FFE) controllerX = -0x7FFE;
|
||||
CGFloat controllerY = 0x7FFE * deltaY / 50;
|
||||
CGFloat controllerY = 0x7FFE * deltaY / 35;
|
||||
if(controllerY > 0x7FFE) controllerY = 0x7FFE;
|
||||
if(controllerY < -0x7FFE) controllerY = -0x7FFE;
|
||||
[_controllerSupport updateLeftStick:_controller x: controllerX y: - controllerY]; // stick value populated to the controllerSupport here
|
||||
[_controllerSupport updateFinished:_controller];
|
||||
}
|
||||
|
||||
|
||||
- (void) clearRightStickTouchPadFlag{
|
||||
[_controllerSupport updateRightStick:_controller x:0 y:0];
|
||||
[_controllerSupport clearButtonFlag:_controller flags:RS_CLK_FLAG];
|
||||
[_controllerSupport updateFinished:_controller];
|
||||
}
|
||||
|
||||
- (void) clearLeftStickTouchPadFlag{
|
||||
[_controllerSupport updateLeftStick:_controller x:0 y:0];
|
||||
[_controllerSupport clearButtonFlag:_controller flags:LS_CLK_FLAG];
|
||||
|
||||
+3
-2
@@ -335,8 +335,9 @@
|
||||
NSString *keyLabel = alertController.textFields[1].text;
|
||||
if([keyLabel isEqualToString:@""]) keyLabel = [[cmdString lowercaseString] capitalizedString];
|
||||
bool noValidKeyboardString = [CommandManager.shared extractKeyStringsFrom:cmdString] == nil; // this is a invalid string.
|
||||
bool noVliadMouseButtongString = ![CommandManager.mouseButtonMappings.allKeys containsObject:cmdString];
|
||||
if(noValidKeyboardString && noVliadMouseButtongString) return;
|
||||
bool noValidMouseButtonString = ![CommandManager.mouseButtonMappings.allKeys containsObject:cmdString];
|
||||
bool noValidTouchPadString = ![CommandManager.touchPadCmds containsObject:cmdString];
|
||||
if(noValidKeyboardString && noValidMouseButtonString && noValidTouchPadString) return;
|
||||
|
||||
//saving & present the keyboard button:
|
||||
OnScreenButtonView* buttonView = [[OnScreenButtonView alloc] initWithKeyString:cmdString keyLabel:keyLabel];
|
||||
|
||||
Reference in New Issue
Block a user