Skip to content

Commit a6cc10e

Browse files
susnuxAntreesy
authored andcommitted
fixup! adjust docs
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
1 parent f54c6b3 commit a6cc10e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

docs/composables/useHotKey.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ const stopCallback = useHotKey(key, callback, options)
1414
```
1515
where:
1616
- `keysOrFilter`: one of following:
17-
- `string`: representing the keyboard key to listen to
18-
- `Array<string>`: representing any of keys to listen to
17+
- `string`: representing the keyboard key or code to listen to (e.g. `'a'` or `'KeyA'`)
18+
- `Array<string>`: representing any of keys or codes to listen to (e.g. `['a', 'KeyA']`)
1919
- `Function`: custom filter function to validate event key
2020
- `true`: to listen for all events
2121

22-
See [KeyboardEvent.key Value column](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values) for possible values
22+
See [KeyboardEvent.key Value column](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values) and [KeyboardEvent.code Value columns](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_code_values) for possible values.
23+
Try to use `KeyboardEvent.code` instead of `KeyboardEvent.key` when possible, as it works more reliable across different keyboard layouts (e.g. Latin / Cyrillic).
24+
Codes are still layout-dependent, so try to avoid using codes that can be located in different places on the keyboard, like `QWERTZ` or `AZERTY` layouts.
25+
2326
- `callback`: a function to be called when the key is pressed. Before called, it will be checked whether keyboard shortcuts are disabled, or interactive element is currently focused, or whether options should be applied
2427
- `options`: options to be applied to the shortcut:
2528
- `push`: whether the event should be triggered on both keydown and keyup (default: `false`)
@@ -105,10 +108,10 @@ where:
105108
}
106109
107110
useHotKey(true, updateLoggedKey)
108-
useHotKey(['w', 'KeyW'], moveUp)
109-
useHotKey(['s', 'KeyS'], moveDown)
110-
useHotKey(['a', 'KeyA'], moveLeft)
111-
useHotKey(['d', 'KeyD'], moveRight)
111+
useHotKey('KeyW', moveUp)
112+
useHotKey('KeyS', moveDown)
113+
useHotKey('KeyA', moveLeft)
114+
useHotKey('KeyD', moveRight)
112115
const stop = useHotKey('m', toggleHighlighted, { push: true })
113116
114117
return {

0 commit comments

Comments
 (0)