Add key combo support

This commit is contained in:
xzzpig
2024-12-01 18:16:46 +08:00
parent 62ae63d7f6
commit a0f13881bf
4 changed files with 71 additions and 0 deletions
+3
View File
@@ -248,6 +248,9 @@
case UIKeyboardHIDUsageKeyboardRightAlt:
keyCode = 0xA5;
break;
case UIKeyboardHIDUsageKeyboardErrorUndefined:
NSLog(@"Undefined key pressed");
return false;
case 669: // This value corresponds to the "Globe" or "Language" key on most Apple branded iPad keyboards.
keyCode = 0x1B; // This value corresponds to "Escape", which is missing from most Apple branded iPad keyboards.
break;
+4
View File
@@ -15,6 +15,10 @@
- (void) userInteractionBegan;
- (void) userInteractionEnded;
- (void) streamExitRequested;
- (void) toggleStatsOverlay;
- (void) toggleMouseCapture;
- (void) toggleMouseVisible;
@end
+26
View File
@@ -64,12 +64,15 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
UIHoverGestureRecognizer *stylusHoverRecognizer;
#endif
CGFloat HeightViewLiftedTo;
UIKeyModifierFlags comboKeyModifierFlags;
}
- (void) setupStreamView:(ControllerSupport*)controllerSupport
interactionDelegate:(id<UserInteractionDelegate>)interactionDelegate
config:(StreamConfiguration*)streamConfig
streamFrameTopLayerView:(UIView* )topLayerView{
self->comboKeyModifierFlags = (UIKeyModifierControl|UIKeyModifierAlternate|UIKeyModifierShift);
self->streamFrameTopLayerView = topLayerView;
self.streamFrameTopLayerView = topLayerView; // this will be used as a read-only pointer for other class
@@ -755,11 +758,34 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
else if(![onScreenControls handleTouchMovedEvent:touches]) [touchHandler touchesMoved:touches withEvent:event];
}
- (void) handleKeyCombos:(UIPress*) press{
if(press.key.modifierFlags != comboKeyModifierFlags){
return;
}
switch (press.key.keyCode) {
case UIKeyboardHIDUsageKeyboardQ:
[interactionDelegate streamExitRequested];
break;
case UIKeyboardHIDUsageKeyboardS:
[interactionDelegate toggleStatsOverlay];
break;
case UIKeyboardHIDUsageKeyboardM:
[interactionDelegate toggleMouseCapture];
break;
case UIKeyboardHIDUsageKeyboardC:
[interactionDelegate toggleMouseVisible];
break;
default:
break;
}
}
- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event {
BOOL handled = NO;
if (@available(iOS 13.4, tvOS 13.4, *)) {
for (UIPress* press in presses) {
[self handleKeyCombos:press];
// For now, we'll treated it as handled if we handle at least one of the
// UIPress events inside the set.
if ([KeyboardSupport sendKeyEventForPress:press down:YES]) {
@@ -936,6 +936,44 @@
#endif
}
- (void)toggleStatsOverlay{
DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings];
currentSettings.statsOverlay = !currentSettings.statsOverlay;
[dataMan saveData];
[self reConfigStreamViewRealtime];
}
- (void)toggleMouseCapture{
DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings];
if(currentSettings.mouseMode.intValue == 0){
currentSettings.mouseMode = @1;
}else{
currentSettings.mouseMode = @0;
}
[dataMan saveData];
[self reConfigStreamViewRealtime];
}
- (void)toggleMouseVisible{
DataManager* dataMan = [[DataManager alloc] init];
Settings *currentSettings = [dataMan retrieveSettings];
if(currentSettings.mouseMode.intValue == 2){
currentSettings.mouseMode = @1;
}else{
currentSettings.mouseMode = @2;
}
[dataMan saveData];
[self reConfigStreamViewRealtime];
}
#if !TARGET_OS_TV
// Require a confirmation when streaming to activate a system gesture
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {