-
Notifications
You must be signed in to change notification settings - Fork 5
Handling Keyboard Inputs with Active Patterns
MIkE edited this page Sep 19, 2018
·
6 revisions
An active pattern lets you define match expressions with different number of Keys to analyse keyboard input.
Define active pattern:
let (|ContainsKeys|_|) (keys : List<Keys>) (pressedKeys : Set<Keys>) : unit option =
match containsKeys pressedKeys keys with
| true -> Some ()
| false -> None
Match expression:
match pressedKeys with
| KeysSet.ContainsKeys [ Keys.P; Keys.LeftCtrl ]
| KeysSet.ContainsKeys [ Keys.P; Keys.RightCtrl ] -> ()
| KeysSet.ContainsKey Keys.OemPeriod -> ()
| KeysSet.ContainsKeys [ Keys.LeftCtrl; Keys.LeftAlt; Keys.Delete ] -> ()
- Boolean Queries
- List to keep KeyPress order