isModifierPressed method

  1. @override
bool isModifierPressed(
  1. ModifierKey key,
  2. {KeyboardSide side = KeyboardSide.any}

Returns true if the given ModifierKey was pressed at the time of this event.

This method is deprecated and will be removed. For equivalent information, inspect HardwareKeyboard.logicalKeysPressed instead.

If side is specified, then this restricts its check to the specified side of the keyboard. Defaults to checking for the key being down on either side of the keyboard. If there is only one instance of the key on the keyboard, then side is ignored.


bool isModifierPressed(ModifierKey key, {KeyboardSide side = KeyboardSide.any}) {
  final int independentModifier = modifiers & deviceIndependentMask;
  bool result;
  switch (key) {
    case ModifierKey.controlModifier:
      result = _isLeftRightModifierPressed(side, independentModifier & modifierControl, modifierLeftControl, modifierRightControl);
    case ModifierKey.shiftModifier:
      result = _isLeftRightModifierPressed(side, independentModifier & modifierShift, modifierLeftShift, modifierRightShift);
    case ModifierKey.altModifier:
      result = _isLeftRightModifierPressed(side, independentModifier & modifierOption, modifierLeftOption, modifierRightOption);
    case ModifierKey.metaModifier:
      result = _isLeftRightModifierPressed(side, independentModifier & modifierCommand, modifierLeftCommand, modifierRightCommand);
    case ModifierKey.capsLockModifier:
      result = independentModifier & modifierCapsLock != 0;
  // On iOS, the function modifier bit is set for any function key, like F1,
  // F2, etc., but the meaning of ModifierKey.modifierFunction in Flutter is
  // that of the Fn modifier key, so there's no good way to emulate that on
  // iOS.
    case ModifierKey.functionModifier:
    case ModifierKey.numLockModifier:
    case ModifierKey.symbolModifier:
    case ModifierKey.scrollLockModifier:
      // These modifier masks are not used in iOS keyboards.
      result = false;
  assert(!result || getModifierSide(key) != null, "$runtimeType thinks that a modifier is pressed, but can't figure out what side it's on.");
  return result;