Skip to content

Commit 513d22c

Browse files
feat(hotkeys): add numpad key support
1 parent 8073e45 commit 513d22c

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

.changeset/numpad-keys-support.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/hotkeys': minor
3+
---
4+
5+
Add numpad key support with NumpadKey type including Numpad0-9, NumpadAdd, NumpadSubtract, NumpadMultiply, NumpadDivide, NumpadDecimal, and NumpadEnter

packages/hotkeys/src/constants.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
LetterKey,
66
NavigationKey,
77
NumberKey,
8+
NumpadKey,
89
PunctuationKey,
910
} from './hotkey'
1011

@@ -300,6 +301,35 @@ export const PUNCTUATION_KEYS = new Set<PunctuationKey>([
300301
'`',
301302
])
302303

304+
/**
305+
* Set of all valid numpad keys.
306+
*
307+
* Numpad keys are commonly used for data entry and calculator-style input.
308+
* They produce distinct `event.key` values from the main number row:
309+
* - `Numpad0`-`Numpad9` for digits
310+
* - `NumpadAdd`, `NumpadSubtract`, `NumpadMultiply`, `NumpadDivide` for operators
311+
* - `NumpadDecimal` for the decimal point
312+
* - `NumpadEnter` for the numpad enter key
313+
*/
314+
export const NUMPAD_KEYS = new Set<NumpadKey>([
315+
'Numpad0',
316+
'Numpad1',
317+
'Numpad2',
318+
'Numpad3',
319+
'Numpad4',
320+
'Numpad5',
321+
'Numpad6',
322+
'Numpad7',
323+
'Numpad8',
324+
'Numpad9',
325+
'NumpadAdd',
326+
'NumpadSubtract',
327+
'NumpadMultiply',
328+
'NumpadDivide',
329+
'NumpadDecimal',
330+
'NumpadEnter',
331+
])
332+
303333
/**
304334
* Set of all valid non-modifier keys.
305335
*
@@ -321,6 +351,7 @@ export const ALL_KEYS = new Set([
321351
...NAVIGATION_KEYS,
322352
...EDITING_KEYS,
323353
...PUNCTUATION_KEYS,
354+
...NUMPAD_KEYS,
324355
])
325356

326357
/**
@@ -393,6 +424,24 @@ const KEY_ALIASES: Record<string, string> = {
393424
PgDn: 'PageDown',
394425
pgup: 'PageUp',
395426
pgdn: 'PageDown',
427+
428+
// Numpad variants (lowercase aliases)
429+
numpad0: 'Numpad0',
430+
numpad1: 'Numpad1',
431+
numpad2: 'Numpad2',
432+
numpad3: 'Numpad3',
433+
numpad4: 'Numpad4',
434+
numpad5: 'Numpad5',
435+
numpad6: 'Numpad6',
436+
numpad7: 'Numpad7',
437+
numpad8: 'Numpad8',
438+
numpad9: 'Numpad9',
439+
numpadadd: 'NumpadAdd',
440+
numpadsubtract: 'NumpadSubtract',
441+
numpadmultiply: 'NumpadMultiply',
442+
numpaddivide: 'NumpadDivide',
443+
numpaddecimal: 'NumpadDecimal',
444+
numpadenter: 'NumpadEnter',
396445
}
397446

398447
/**

packages/hotkeys/src/hotkey.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ export type PunctuationKey =
125125
| '.'
126126
| '`'
127127

128+
/**
129+
* Numpad keys for numeric keypad operations.
130+
* These keys are commonly used for data entry and calculator-style input.
131+
*/
132+
export type NumpadKey =
133+
| 'Numpad0'
134+
| 'Numpad1'
135+
| 'Numpad2'
136+
| 'Numpad3'
137+
| 'Numpad4'
138+
| 'Numpad5'
139+
| 'Numpad6'
140+
| 'Numpad7'
141+
| 'Numpad8'
142+
| 'Numpad9'
143+
| 'NumpadAdd'
144+
| 'NumpadSubtract'
145+
| 'NumpadMultiply'
146+
| 'NumpadDivide'
147+
| 'NumpadDecimal'
148+
| 'NumpadEnter'
149+
128150
/**
129151
* Keys that don't change their value when Shift is pressed.
130152
* These keys produce the same `KeyboardEvent.key` value whether Shift is held or not.
@@ -141,6 +163,7 @@ type NonPunctuationKey =
141163
| EditingKey
142164
| NavigationKey
143165
| FunctionKey
166+
| NumpadKey
144167

145168
/**
146169
* All supported non-modifier keys.

0 commit comments

Comments
 (0)