5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterChannelKeyResponder.h"
7#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
8#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUIPressProxy.h"
9#import "flutter/shell/platform/darwin/ios/framework/Source/KeyCodeMap_Internal.h"
20 kKeyboardModifierAlphaShift = 0x10000,
21 kKeyboardModifierShift = 0x20000,
22 kKeyboardModifierLeftShift = 0x02,
23 kKeyboardModifierRightShift = 0x04,
24 kKeyboardModifierControl = 0x40000,
25 kKeyboardModifierLeftControl = 0x01,
26 kKeyboardModifierRightControl = 0x2000,
27 kKeyboardModifierOption = 0x80000,
28 kKeyboardModifierLeftOption = 0x20,
29 kKeyboardModifierRightOption = 0x40,
30 kKeyboardModifierCommand = 0x100000,
31 kKeyboardModifierLeftCommand = 0x08,
32 kKeyboardModifierRightCommand = 0x10,
33 kKeyboardModifierNumericPad = 0x200000,
34 kKeyboardModifierMask = kKeyboardModifierAlphaShift |
35 kKeyboardModifierShift |
36 kKeyboardModifierLeftShift |
37 kKeyboardModifierRightShift |
38 kKeyboardModifierControl |
39 kKeyboardModifierLeftControl |
40 kKeyboardModifierRightControl |
41 kKeyboardModifierOption |
42 kKeyboardModifierLeftOption |
43 kKeyboardModifierRightOption |
44 kKeyboardModifierCommand |
45 kKeyboardModifierLeftCommand |
46 kKeyboardModifierRightCommand |
47 kKeyboardModifierNumericPad,
55 if (characters == nil) {
58 if ([characters
length] == 0) {
61 if (@available(iOS 13.4, *)) {
98 _pressedModifiers = 0;
105 if (@available(iOS 13.4, *)) {
111 switch (press.phase) {
112 case UIPressPhaseBegan:
115 case UIPressPhaseCancelled:
120 case UIPressPhaseEnded:
123 case UIPressPhaseChanged:
126 case UIPressPhaseStationary:
136 NSString* charactersIgnoringModifiers =
138 NSDictionary* keyMessage = @{
141 @"keyCode" : @(press.key.keyCode),
142 @"modifiers" : @([
self adjustModifiers:press]),
143 @"characters" : characters == nil ?
@"" : characters,
144 @"charactersIgnoringModifiers" : charactersIgnoringModifiers == nil
146 : charactersIgnoringModifiers,
148 [
self.channel sendMessage:keyMessage
150 bool handled = reply ? [[reply valueForKey:@"handled"] boolValue] : true;
155#pragma mark - Private
158 if (@available(iOS 13.4, *)) {
165 switch (press.phase) {
166 case UIPressPhaseStationary:
167 case UIPressPhaseChanged:
169 NSAssert(
false,
@"Unexpected key event type received in updatePressedModifiers.");
171 case UIPressPhaseBegan:
174 case UIPressPhaseCancelled:
175 case UIPressPhaseEnded:
180 void (^
update)(kKeyboardModifier, bool) = ^(kKeyboardModifier mod,
bool isOn) {
182 _pressedModifiers |= mod;
184 _pressedModifiers &= ~mod;
187 switch (press.key.keyCode) {
188 case UIKeyboardHIDUsageKeyboardCapsLock:
191 case UIKeyboardHIDUsageKeypadNumLock:
194 case UIKeyboardHIDUsageKeyboardLeftShift:
197 case UIKeyboardHIDUsageKeyboardRightShift:
200 case UIKeyboardHIDUsageKeyboardLeftControl:
203 case UIKeyboardHIDUsageKeyboardRightControl:
206 case UIKeyboardHIDUsageKeyboardLeftAlt:
209 case UIKeyboardHIDUsageKeyboardRightAlt:
212 case UIKeyboardHIDUsageKeyboardLeftGUI:
215 case UIKeyboardHIDUsageKeyboardRightGUI:
223 update(kKeyboardModifierShift,
224 _pressedModifiers & (kKeyboardModifierRightShift | kKeyboardModifierLeftShift));
225 update(kKeyboardModifierControl,
226 _pressedModifiers & (kKeyboardModifierRightControl | kKeyboardModifierLeftControl));
227 update(kKeyboardModifierOption,
228 _pressedModifiers & (kKeyboardModifierRightOption | kKeyboardModifierLeftOption));
229 update(kKeyboardModifierCommand,
230 _pressedModifiers & (kKeyboardModifierRightCommand | kKeyboardModifierLeftCommand));
237 if (@available(iOS 13.4, *)) {
240 return press.key.modifierFlags;
243 [
self updatePressedModifiers:press];
245 return _pressedModifiers | (press.key.modifierFlags & ~kKeyboardModifierMask);
FlutterMethodChannel * _channel
FlutterBasicMessageChannel * channel
kKeyboardModifier pressedModifiers
void(^ FlutterAsyncKeyCallback)(BOOL handled)
const std::set< uint32_t > functionKeyCodes
static NSString * getEventCharacters(NSString *characters, UIKeyboardHIDUsage keyCode) API_AVAILABLE(ios(13.4))
static bool isKeyDown(FlutterUIPressProxy *press) API_AVAILABLE(ios(13.4))
typedef NS_OPTIONS(NSInteger, kKeyboardModifier)
SK_API sk_sp< SkSurface > ios(9.0)
API_AVAILABLE(ios(14.0), macos(11.0)) static NSString *MTLCommandEncoderErrorStateToString(MTLCommandEncoderErrorState state)