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.

This method is deprecated and will be removed.

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. If the given platform does not specify the side, return KeyboardSide.any.

Implementation

@override
KeyboardSide? getModifierSide(ModifierKey key) {
  KeyboardSide? findSide(int anyMask, int leftMask, int rightMask) {
    final int combinedMask = leftMask | rightMask;
    final int combined = metaState & combinedMask;
    if (combined == leftMask) {
      return KeyboardSide.left;
    } else if (combined == rightMask) {
      return KeyboardSide.right;
    } else if (combined == combinedMask) {
      return KeyboardSide.all;
    }
    // If the platform code sets the "any" modifier, but not a specific side,
    // then we return "all", assuming that there is only one of that modifier
    // key on the keyboard.
    if (metaState & anyMask != 0) {
      return KeyboardSide.all;
    }
    return null;
  }

  switch (key) {
    case ModifierKey.controlModifier:
      return findSide(modifierControl, modifierLeftControl, modifierRightControl);
    case ModifierKey.shiftModifier:
      return findSide(modifierShift, modifierLeftShift, modifierRightShift);
    case ModifierKey.altModifier:
      return findSide(modifierAlt, modifierLeftAlt, modifierRightAlt);
    case ModifierKey.metaModifier:
      return findSide(modifierMeta, modifierLeftMeta, modifierRightMeta);
    case ModifierKey.capsLockModifier:
    case ModifierKey.numLockModifier:
    case ModifierKey.scrollLockModifier:
    case ModifierKey.functionModifier:
    case ModifierKey.symbolModifier:
      return KeyboardSide.all;
  }
}