handleKeyEvent method

bool handleKeyEvent(
  1. KeyEvent event
)

Process a new KeyEvent by recording the state changes and dispatching to handlers.

Implementation

bool handleKeyEvent(KeyEvent event) {
  assert(_keyboardDebug(() => 'Key event received: $event'));
  assert(_keyboardDebug(() => 'Pressed state before processing the event:', _debugPressedKeysDetails));
  _assertEventIsRegular(event);
  final PhysicalKeyboardKey physicalKey = event.physicalKey;
  final LogicalKeyboardKey logicalKey = event.logicalKey;
  if (event is KeyDownEvent) {
    _pressedKeys[physicalKey] = logicalKey;
    final KeyboardLockMode? lockMode = KeyboardLockMode.findLockByLogicalKey(event.logicalKey);
    if (lockMode != null) {
      if (_lockModes.contains(lockMode)) {
        _lockModes.remove(lockMode);
      } else {
        _lockModes.add(lockMode);
      }
    }
  } else if (event is KeyUpEvent) {
    _pressedKeys.remove(physicalKey);
  } else if (event is KeyRepeatEvent) {
    // Empty
  }

  assert(_keyboardDebug(() => 'Pressed state after processing the event:', _debugPressedKeysDetails));
  return _dispatchKeyEvent(event);
}