Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertWHurst authored Sep 19, 2024
1 parent d44bac0 commit 1c06cab
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import { bindKey, bindKeyCombo } from '@rwh/keystrokes'
bindKey('a', () =>
console.log('You\'re pressing "a"'))

bindKeyCombo('ctrl > y, r', () =>
console.log('You pressed "ctrl" then "y", released both, and are pressing "r"'))
bindKeyCombo('control > y, r', () =>
console.log('You pressed "control" then "y", released both, and are pressing "r"'))
```

## Installation
Expand Down Expand Up @@ -142,18 +142,18 @@ import { bindKey, bindKeyCombo } from '@rwh/keystrokes'
bindKey('a', () =>
console.log('You\'re pressing "a"'))

bindKeyCombo('ctrl > y, r', () =>
console.log('You pressed "ctrl" then "y", released both, and are pressing "r"'))
bindKeyCombo('control > y, r', () =>
console.log('You pressed "control" then "y", released both, and are pressing "r"'))

bindKey('a', {
onPressed: () => console.log('You pressed "a"'),
onPressedWithRepeat: () => console.log('You\'re pressing "a"'),
onReleased: () => console.log('You released "a"'),
})

bindKeyCombo('ctrl > y, r', {
onPressed: () => console.log('You pressed "ctrl" then "y", released both, then pressed "r"'),
onPressedWithRepeat: () => console.log('You pressed "ctrl" then "y", released both, and are pressing "r"'),
bindKeyCombo('control > y, r', {
onPressed: () => console.log('You pressed "control" then "y", released both, then pressed "r"'),
onPressedWithRepeat: () => console.log('You pressed "control" then "y", released both, and are pressing "r"'),
onReleased: () => console.log('You released "r"'),
})
```
Expand All @@ -162,11 +162,11 @@ Note that when you pass a function handler instead of an object handler, it is
short hand for passing an object handler with a `onPressedWithRepeat` method.

```js
const handler = () => console.log('You pressed "ctrl" then "y", released both, and are pressing "r"')
const handler = () => console.log('You pressed "control" then "y", released both, and are pressing "r"')

bindKeyCombo('ctrl > y, r', handler)
bindKeyCombo('control > y, r', handler)
// ...is shorthand for...
bindKeyCombo('ctrl > y, r', { onPressedWithRepeat: handler })
bindKeyCombo('control > y, r', { onPressedWithRepeat: handler })
```

## Unbinding Keys and Key Combos
Expand All @@ -181,20 +181,20 @@ import { bindKeyCombo, unbindKeyCombo } from '@rwh/keystrokes'
const handler = () => ...

// bind the combo to the handler
bindKeyCombo('ctrl > y, r', handler)
bindKeyCombo('control > y, r', handler)

// ...and some time later...

// unbind the handler
unbindKeyCombo('ctrl > y, r', handler)
unbindKeyCombo('control > y, r', handler)
```

You can also wipe out all bound handlers on a combo by excluding a handler
reference.

```js
// unbind all handlers for the combo 'ctrl > y, r'
unbindKeyCombo('ctrl > y, r')
// unbind all handlers for the combo 'control > y, r'
unbindKeyCombo('control > y, r')
```

## Checking Keys and Key Combos
Expand All @@ -208,9 +208,9 @@ import { checkKey, checkKeyCombo } from '@rwh/keystrokes'
// keyIsPressed will be true if a is pressed, and false otherwise
const keyIsPressed = checkKey('a')

// keyComboIsPressed will be true if ctrl then y was pressed and r is pressed.
// keyComboIsPressed will be true if control then y was pressed and r is pressed.
// It will be false otherwise.
const keyComboIsPressed = checkKeyCombo('ctrl > y, r')
const keyComboIsPressed = checkKeyCombo('control > y, r')
```

## Using Keystrokes with React
Expand Down

0 comments on commit 1c06cab

Please sign in to comment.