|
@@ -19,6 +19,7 @@
|
|
|
@property (nonatomic, strong) NSString *_unmodifiedInput;
|
|
@property (nonatomic, strong) NSString *_unmodifiedInput;
|
|
|
@property (nonatomic, assign) UIKeyModifierFlags _modifierFlags;
|
|
@property (nonatomic, assign) UIKeyModifierFlags _modifierFlags;
|
|
|
@property (nonatomic, assign) BOOL _isKeyDown;
|
|
@property (nonatomic, assign) BOOL _isKeyDown;
|
|
|
|
|
+@property (nonatomic, assign) long _keyCode;
|
|
|
|
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
@@ -114,6 +115,10 @@
|
|
|
|
|
|
|
|
@property (nonatomic, strong) NSMutableDictionary *actionsForKeyInputs;
|
|
@property (nonatomic, strong) NSMutableDictionary *actionsForKeyInputs;
|
|
|
|
|
|
|
|
|
|
+@property (nonatomic, assign, getter=isPressingShift) BOOL pressingShift;
|
|
|
|
|
+@property (nonatomic, assign, getter=isPressingCommand) BOOL pressingCommand;
|
|
|
|
|
+@property (nonatomic, assign, getter=isPressingControl) BOOL pressingControl;
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation FLEXKeyboardShortcutManager
|
|
@implementation FLEXKeyboardShortcutManager
|
|
@@ -133,14 +138,52 @@
|
|
|
SEL originalKeyEventSelector = NSSelectorFromString(@"handleKeyUIEvent:");
|
|
SEL originalKeyEventSelector = NSSelectorFromString(@"handleKeyUIEvent:");
|
|
|
SEL swizzledKeyEventSelector = [FLEXUtility swizzledSelectorForSelector:originalKeyEventSelector];
|
|
SEL swizzledKeyEventSelector = [FLEXUtility swizzledSelectorForSelector:originalKeyEventSelector];
|
|
|
|
|
|
|
|
- void (^sendEventSwizzleBlock)(UIApplication *, UIEvent *) = ^(UIApplication *slf, UIEvent *event) {
|
|
|
|
|
|
|
+ void (^handleKeyUIEventSwizzleBlock)(UIApplication *, UIEvent *) = ^(UIApplication *slf, UIEvent *event) {
|
|
|
|
|
|
|
|
[[[self class] sharedManager] handleKeyboardEvent:event];
|
|
[[[self class] sharedManager] handleKeyboardEvent:event];
|
|
|
|
|
|
|
|
((void(*)(id, SEL, id))objc_msgSend)(slf, swizzledKeyEventSelector, event);
|
|
((void(*)(id, SEL, id))objc_msgSend)(slf, swizzledKeyEventSelector, event);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- [FLEXUtility replaceImplementationOfKnownSelector:originalKeyEventSelector onClass:[UIApplication class] withBlock:sendEventSwizzleBlock swizzledSelector:swizzledKeyEventSelector];
|
|
|
|
|
|
|
+ [FLEXUtility replaceImplementationOfKnownSelector:originalKeyEventSelector onClass:[UIApplication class] withBlock:handleKeyUIEventSwizzleBlock swizzledSelector:swizzledKeyEventSelector];
|
|
|
|
|
+
|
|
|
|
|
+ SEL originalSendEventSelector = NSSelectorFromString(@"sendEvent:");
|
|
|
|
|
+ SEL swizzledSendEventSelector = [FLEXUtility swizzledSelectorForSelector:originalSendEventSelector];
|
|
|
|
|
+
|
|
|
|
|
+ void (^sendEventSwizzleBlock)(UIApplication *, UIEvent *) = ^(UIApplication *slf, UIEvent *event) {
|
|
|
|
|
+ if (event.type == UIEventTypeTouches) {
|
|
|
|
|
+ FLEXKeyboardShortcutManager *keyboardManager = [FLEXKeyboardShortcutManager sharedManager];
|
|
|
|
|
+ NSInteger pressureLevel = 0;
|
|
|
|
|
+ if (keyboardManager.isPressingShift) {
|
|
|
|
|
+ pressureLevel++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (keyboardManager.isPressingCommand) {
|
|
|
|
|
+ pressureLevel++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (keyboardManager.isPressingControl) {
|
|
|
|
|
+ pressureLevel++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (pressureLevel > 0) {
|
|
|
|
|
+ for (UITouch *touch in [event allTouches]) {
|
|
|
|
|
+ double adjustedPressureLevel = pressureLevel * 20 * touch.maximumPossibleForce;
|
|
|
|
|
+ [touch setValue:@(adjustedPressureLevel) forKey:@"_pressure"];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ((void(*)(id, SEL, id))objc_msgSend)(slf, swizzledSendEventSelector, event);
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ [FLEXUtility replaceImplementationOfKnownSelector:originalSendEventSelector onClass:[UIApplication class] withBlock:sendEventSwizzleBlock swizzledSelector:swizzledSendEventSelector];
|
|
|
|
|
+
|
|
|
|
|
+ SEL originalSupportsTouchPressureSelector = NSSelectorFromString(@"_supportsForceTouch");
|
|
|
|
|
+ SEL swizzledSupportsTouchPressureSelector = [FLEXUtility swizzledSelectorForSelector:originalSupportsTouchPressureSelector];
|
|
|
|
|
+
|
|
|
|
|
+ BOOL (^supportsTouchPressureSwizzleBlock)(UIDevice *) = ^BOOL(UIDevice *slf) {
|
|
|
|
|
+ return YES;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ [FLEXUtility replaceImplementationOfKnownSelector:originalSupportsTouchPressureSelector onClass:[UIDevice class] withBlock:supportsTouchPressureSwizzleBlock swizzledSelector:swizzledSupportsTouchPressureSelector];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
- (instancetype)init
|
|
@@ -161,6 +204,10 @@
|
|
|
[self.actionsForKeyInputs setObject:action forKey:keyInput];
|
|
[self.actionsForKeyInputs setObject:action forKey:keyInput];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+static const long kFLEXControlKeyCode = 0xe0;
|
|
|
|
|
+static const long kFLEXShiftKeyCode = 0xe1;
|
|
|
|
|
+static const long kFLEXCommandKeyCode = 0xe3;
|
|
|
|
|
+
|
|
|
- (void)handleKeyboardEvent:(UIEvent *)event
|
|
- (void)handleKeyboardEvent:(UIEvent *)event
|
|
|
{
|
|
{
|
|
|
if (!self.enabled) {
|
|
if (!self.enabled) {
|
|
@@ -171,6 +218,7 @@
|
|
|
NSString *unmodifiedInput = nil;
|
|
NSString *unmodifiedInput = nil;
|
|
|
UIKeyModifierFlags flags = 0;
|
|
UIKeyModifierFlags flags = 0;
|
|
|
BOOL isKeyDown = NO;
|
|
BOOL isKeyDown = NO;
|
|
|
|
|
+ long keyCode = 0;
|
|
|
|
|
|
|
|
if ([event respondsToSelector:@selector(_modifiedInput)]) {
|
|
if ([event respondsToSelector:@selector(_modifiedInput)]) {
|
|
|
modifiedInput = [event _modifiedInput];
|
|
modifiedInput = [event _modifiedInput];
|
|
@@ -188,6 +236,10 @@
|
|
|
isKeyDown = [event _isKeyDown];
|
|
isKeyDown = [event _isKeyDown];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ([event respondsToSelector:@selector(_keyCode)]) {
|
|
|
|
|
+ keyCode = [event _keyCode];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
BOOL interactionEnabled = ![[UIApplication sharedApplication] isIgnoringInteractionEvents];
|
|
BOOL interactionEnabled = ![[UIApplication sharedApplication] isIgnoringInteractionEvents];
|
|
|
|
|
|
|
|
if (isKeyDown && [modifiedInput length] > 0 && interactionEnabled) {
|
|
if (isKeyDown && [modifiedInput length] > 0 && interactionEnabled) {
|
|
@@ -224,6 +276,14 @@
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (keyCode == kFLEXControlKeyCode) {
|
|
|
|
|
+ self.pressingControl = isKeyDown;
|
|
|
|
|
+ } else if (keyCode == kFLEXCommandKeyCode) {
|
|
|
|
|
+ self.pressingCommand = isKeyDown;
|
|
|
|
|
+ } else if (keyCode == kFLEXShiftKeyCode) {
|
|
|
|
|
+ self.pressingShift = isKeyDown;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)keyboardShortcutsDescription
|
|
- (NSString *)keyboardShortcutsDescription
|