isModifierPressed method Null safety
- ModifierKey key,
- {KeyboardSide side = KeyboardSide.any}
override
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.
Implementation
@override
bool isModifierPressed(ModifierKey key, {KeyboardSide side = KeyboardSide.any}) {
final bool result;
switch (key) {
case ModifierKey.controlModifier:
result = _isLeftRightModifierPressed(side, modifierControl, modifierLeftControl, modifierRightControl);
break;
case ModifierKey.shiftModifier:
result = _isLeftRightModifierPressed(side, modifierShift, modifierLeftShift, modifierRightShift);
break;
case ModifierKey.altModifier:
result = _isLeftRightModifierPressed(side, modifierAlt, modifierLeftAlt, modifierRightAlt);
break;
case ModifierKey.metaModifier:
// Windows does not provide an "any" key for win key press.
result = _isLeftRightModifierPressed(side, modifierLeftMeta | modifierRightMeta , modifierLeftMeta, modifierRightMeta);
break;
case ModifierKey.capsLockModifier:
result = modifiers & modifierCaps != 0;
break;
case ModifierKey.scrollLockModifier:
result = modifiers & modifierScrollLock != 0;
break;
case ModifierKey.numLockModifier:
result = modifiers & modifierNumLock != 0;
break;
// 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;
break;
}
assert(!result || getModifierSide(key) != null, "$runtimeType thinks that a modifier is pressed, but can't figure out what side it's on.");
return result;
}