@@ -11,7 +11,7 @@ Function signature:
1111function isHotkeyPressed(key : string | string [], splitKey : string = ' ,' ): boolean
1212```
1313
14- This function allows us to check if a specific key is pressed by the user.
14+ This function allows us to check if a specific key or combination of keys is pressed by the user.
1515
1616` ` ` jsx
1717const isHotkeyPressed = useIsHotkeyPressed();
@@ -29,19 +29,34 @@ const onClick = () => isHotkeyPressed('shift') ? setCount(count - 1) : setCount(
2929key: string | string[]
3030` ` `
3131
32- The key we want to listen to . This can be a string (like ` 'a' ` , ` 'shift+a' ` ) or an array of strings (like ` ['a', 'shift+a'] ` ).
32+ The key or keys to check . This can be a single keycode string (like ` 'a' ` ), a
33+ delimited string of keycodes (like ` 'shift,a' ` ), or an array of keycode strings
34+ (like ` ['shift','a'] ` ). If multiple keys are provided , either as a delimited
35+ string or as an array , all keys must be pressed down for the function to return
36+ `true`.
37+
38+ Special characters that require ` shift ` to be held (like ` ! ` , ` @ ` , ` # ` , ` ? ` ,
39+ etc .) are also not directly supported ; instead , check if the base key is held
40+ (like ` 1 ` , ` 2 ` , ` 3 ` , ` slash ` , etc .) along with the ` shift ` key (e .g .
41+ ` ['shift','1'] ` ).
42+
43+ :::caution Warning
44+ The ` mod ` key is not supported . Please check for ` ctrl ` and
45+ ` meta ` keys separately .
46+ :::
3347
3448### splitKey
3549
3650` ` ` ts
3751key: string = ','
3852` ` `
3953
40- We can combine to check for multiple keys in one string by separating them with a comma ( ` , ` ). We can change
41- this by passing a different key .
54+ The delimiter used to parse multiple keys from a single string . This is a comma
55+ ( ` , ` ) by default .
4256
4357## Return value
4458
4559### boolean
4660
47- The function returns `true` if the key or keystroke is currently pressed down, otherwise it will return `false`.
61+ The function returns `true` if the key or key combination is currently pressed
62+ down, otherwise it will return `false`.
0 commit comments