Skip to content

Commit

Permalink
fix: #40 normalize checkKey input
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot67 committed Apr 1, 2024
1 parent 05a2d1f commit 1eeab82
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/keystrokes/src/keystrokes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export class Keystrokes<
}

checkKey(key: string) {
key = key.toLowerCase()
return this._activeKeyPresses.some(
(p) => p.key === key || p.aliases.has(key),
)
Expand Down
5 changes: 5 additions & 0 deletions packages/keystrokes/src/tests/keystrokes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,20 @@ describe('new Keystrokes(options)', () => {
const keystrokes = createTestKeystrokes()

expect(keystrokes.checkKey('a')).toBe(false)
expect(keystrokes.checkKey('ArrowRight')).toBe(false)

keystrokes.press({ key: 'a' })
keystrokes.press({ key: 'a' })
keystrokes.press({ key: 'ArrowRight' })

expect(keystrokes.checkKey('a')).toBe(true)
expect(keystrokes.checkKey('ArrowRight')).toBe(true)

keystrokes.release({ key: 'a' })
keystrokes.release({ key: 'ArrowRight' })

expect(keystrokes.checkKey('a')).toBe(false)
expect(keystrokes.checkKey('ArrowRight')).toBe(false)
})

it('will return a boolean indicating if a key is pressed when using aliases', () => {
Expand Down

0 comments on commit 1eeab82

Please sign in to comment.