Skip to content

Commit 0910b21

Browse files
committed
Ignore key if any of alt/ctrl/meta are pressed
1 parent 089ab9e commit 0910b21

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Keyboard.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ let key_of_string = function
1818
| _ -> None
1919
;;
2020

21-
(* TODO: Ignore key when ctrl or cmd are pressed *)
2221
let decode_event =
2322
let open Tea.Json in
24-
Decoder.field "key" Decoder.string |> Decoder.map key_of_string
23+
(* Ignore key if any of alt/ctrl/meta are pressed *)
24+
let ignore_modifier_keys key alt ctrl meta =
25+
if alt || ctrl || meta then None else key_of_string key
26+
in
27+
Decoder.map4
28+
ignore_modifier_keys
29+
(Decoder.field "key" Decoder.string)
30+
(Decoder.field "altKey" Decoder.bool)
31+
(Decoder.field "ctrlKey" Decoder.bool)
32+
(Decoder.field "metaKey" Decoder.bool)
2533
;;
2634

2735
let pressed =

0 commit comments

Comments
 (0)