| Flutter macOS Embedder |

Instance Methods | List of all members
FlutterKeyboardManager Class Reference

`#import <FlutterKeyboardManager.h>`

Inheritance diagram for FlutterKeyboardManager:

## Instance Methods
(nonnull instancetype) | - initWithDelegate:
(void) | - handleEvent:withContext:
(BOOL) | - isDispatchingKeyEvent:
(void) | - syncModifiersIfNeeded:timestamp:
(nonnull NSDictionary *) | - getPressedState
(nonnull instancetype) | - initWithDelegate:keyboardLayout:

## Detailed Description

A hub that manages how key events are dispatched to various Flutter key responders, and whether the event is propagated to the next NSResponder. Cooperates with |TextInputPlugin| to handle text

A keyboard event goes through a few sections, each can choose to handled the event, and only unhandled events can move to the next section:

- Pre-filtering: Events during IME are sent to the system immediately.
- Keyboard: Dispatch to the embedder responder and the channel responder simultaneously. After both responders have responded (asynchronously), the event is considered handled if either responder handles.
- Text input: Events are sent to |TextInputPlugin| and are handled synchronously.
- Next responder: Events are sent to the next responder as specified by |viewDelegate|.

Definition at line 78 of file FlutterKeyboardManager.h.

## Method Documentation

## ◆ getPressedState

- (nonnull NSDictionary *) getPressedState |  |  |

Returns the keyboard pressed state.

Returns the keyboard pressed state. The dictionary contains one entry per pressed keys, mapping from the logical key to the physical key.

Definition at line 92 of file FlutterKeyboardManager.mm.

391 {
392 // The embedder responder is the first element in _primaryResponders.
393 FlutterEmbedderKeyResponder* embedderResponder =
394 (FlutterEmbedderKeyResponder*)_primaryResponders[0];
395 return [embedderResponder getPressedState];
396 }
FlutterEmbedderKeyResponder
Definition: FlutterEmbedderKeyResponder.h:23
-[FlutterEmbedderKeyResponder getPressedState]
nonnull NSDictionary * getPressedState()
Definition: FlutterEmbedderKeyResponder.mm:798

## ◆ handleEvent:withContext:

- (void) handleEvent: |  | (nonnull NSEvent*) | event
withContext: |  | (nonnull id<FlutterKeyboardManagerEventContext>) | eventContext

Processes a key event.

Unhandled events will be dispatched to the text input system, and possibly the next responder afterwards.

Definition at line 92 of file FlutterKeyboardManager.mm.

204 :(nonnull NSEvent*)event
205 withContext:(nonnull id<FlutterKeyboardManagerEventContext>)context {
206 // The `handleEvent` does not process the event immediately, but instead put
207 // events into a queue. Events are processed one by one by `processNextEvent`.
208
209 // Be sure to add a handling method in propagateKeyEvent when allowing more
210 // event types here.
211 if (event.type != NSEventTypeKeyDown && event.type != NSEventTypeKeyUp &&
212 event.type != NSEventTypeFlagsChanged) {
213 return;
214 }
215
216 [_pendingEvents addObject:[[FlutterEventWithContext alloc] initWithEvent:event context:context]];
217 [self processNextEvent];
218 }
FlutterEventWithContext
Definition: FlutterKeyboardManager.mm:48

## ◆ initWithDelegate:

- (nonnull instancetype) initWithDelegate: |  | (nonnull id<FlutterKeyboardManagerDelegate>) | delegate |

Initial value:
{
FlutterKeyboardLayout* _keyboardLayout
FlutterKeyboardLayout
Definition: FlutterKeyboardLayout.h:51

Create a keyboard manager.

The |viewDelegate| is a weak reference, typically implemented by |FlutterViewController|.

Definition at line 92 of file FlutterKeyboardManager.mm.

138 :(nonnull id<FlutterKeyboardManagerDelegate>)delegate {
139 return [self initWithDelegate:delegate keyboardLayout:[[FlutterKeyboardLayout alloc] init]];
140 }

## ◆ initWithDelegate:keyboardLayout:

- (nonnull instancetype) initWithDelegate: |  | (nonnull id< FlutterKeyboardManagerDelegate >) | delegate
keyboardLayout: |  | (nonnull FlutterKeyboardLayout *) | keyboardLayout

Provided by category FlutterKeyboardManager(Testing).

## ◆ isDispatchingKeyEvent:

- (BOOL) isDispatchingKeyEvent: |  | (nonnull NSEvent *) | event |

Returns yes if is event currently being redispatched.

In some instances (i.e. emoji shortcut) the event may be redelivered by cocoa as key equivalent to FlutterTextInput, in which case it shouldn't be processed again.

## ◆ syncModifiersIfNeeded:timestamp:

- (void) syncModifiersIfNeeded: |  | (NSEventModifierFlags) | modifierFlags
timestamp: |  | (NSTimeInterval) | timestamp

Synthesize modifier keys events.

If needed, synthesize modifier keys up and down events by comparing their current pressing states with the given modifier flags.

Definition at line 92 of file FlutterKeyboardManager.mm.

373 :(NSEventModifierFlags)modifierFlags
374 timestamp:(NSTimeInterval)timestamp {
375 for (id<FlutterKeyPrimaryResponder> responder in _primaryResponders) {
376 [responder syncModifiersIfNeeded:modifierFlags timestamp:timestamp];
377 }
378 }

The documentation for this class was generated from the following files:

- shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.h
- shell/platform/darwin/macos/framework/Source/FlutterKeyboardManager.mm