getModifierSide method

  1. @override
KeyboardSide getModifierSide (
  1. ModifierKey key
)
override

Returns a KeyboardSide enum value that describes which side or sides of the given keyboard modifier key were pressed at the time of this event.

If the modifier key wasn't pressed at the time of this event, returns null. If the given key only appears in one place on the keyboard, returns KeyboardSide.all if pressed. Never returns KeyboardSide.any, because that doesn't make sense in this context.

Implementation

@override
KeyboardSide getModifierSide(ModifierKey key) {
  KeyboardSide findSide(int leftMask, int rightMask, int combinedMask) {
    final int combined = modifiers & combinedMask;
    if (combined == leftMask) {
      return KeyboardSide.left;
    } else if (combined == rightMask) {
      return KeyboardSide.right;
    } else if (combined == combinedMask) {
      return KeyboardSide.all;
    }
    return null;
  }

  switch (key) {
    case ModifierKey.controlModifier:
      return findSide(modifierLeftControl, modifierRightControl, modifierControl);
    case ModifierKey.shiftModifier:
      return findSide(modifierLeftShift, modifierRightShift, modifierShift);
    case ModifierKey.altModifier:
      return findSide(modifierLeftAlt, modifierRightAlt, modifierAlt);
    case ModifierKey.metaModifier:
      return findSide(modifierLeftMeta, modifierRightMeta, modifierMeta);
    case ModifierKey.capsLockModifier:
      return (modifiers & modifierCapsLock == 0) ? null : KeyboardSide.all;
    case ModifierKey.numLockModifier:
    case ModifierKey.scrollLockModifier:
    case ModifierKey.functionModifier:
    case ModifierKey.symbolModifier:
      // Fuchsia doesn't support these modifiers, so they can't be pressed.
      return null;
  }

  assert(false, 'Not handling $key type properly.');
  return null;
}