Vixen
02b45cc4
csharp
public static class KeyModifierExtensions

Asking a KeyModifiers the question you meant to ask.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

HasFlag is the wrong operator for the either-side masks, and quietly so. Shift is two bits, so modifiers.HasFlag(KeyModifiers.Shift) asks whether both shift keys are held — which is false in every situation anyone means by "shift is down". The mistake compiles, reads correctly, and produces a shortcut that never fires.

HasAny is what a shortcut wants; HasAll is what a chord wants; Exactly is what distinguishes Ctrl+S from Ctrl+Shift+S and is the one most menu code gets wrong.

Methods (3)

  • public static bool HasAny(this KeyModifiers modifiers, KeyModifiers mask)

    Whether any bit of is held.

  • public static bool HasAll(this KeyModifiers modifiers, KeyModifiers mask)

    Whether every bit of is held.

  • public static bool Exactly(this KeyModifiers modifiers, KeyModifiers mask)

    Whether exactly the modifiers in are held and no others, ignoring the CapsLock and NumLock states.

Used by (2)

  • PlatformEventTestsVixen.Platform.Tests
  • SdlTranslationTestsVixen.Platform.Desktop.Tests