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.

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 bool result;
  switch (key) {
    case ModifierKey.controlModifier:
      result = _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl);
    case ModifierKey.shiftModifier:
      result = _isLeftRightModifierPressed(side, modifierShift, modifierLeftShift, modifierRightShift);
    case ModifierKey.altModifier:
      result = _isLeftRightModifierPressed(side, modifierAlt, modifierLeftAlt, modifierRightAlt);
    case ModifierKey.metaModifier:
      // Windows does not provide an "any" key for win key press.
      result = _isLeftRightModifierPressed(side, modifierLeftMeta | modifierRightMeta , modifierLeftMeta, modifierRightMeta);
    case ModifierKey.capsLockModifier:
      result = modifiers & modifierCaps != 0;
    case ModifierKey.scrollLockModifier:
      result = modifiers & modifierScrollLock != 0;
    case ModifierKey.numLockModifier:
      result = modifiers & modifierNumLock != 0;
    // The OS does not expose the Fn key to the drivers, it doesn't generate a key message.
    case ModifierKey.functionModifier:
    case ModifierKey.symbolModifier:
      // These modifier masks are not used in Windows 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;