Skip to content

Commit

Permalink
Fix doc typo add an example in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed Jan 3, 2024
1 parent 7e21f10 commit 01a868c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# isomorphic-qwerty
Isomorphic coordinate-system for the QWERTY keyboard with sustain using the Shift key

## Installation ##
```bash
npm i
```

## Documentation ##
Documentation is hosted at the project [Github pages](https://xenharmonic-devs.github.io/isomorphic-qwerty).

To generate documentation locally run:
```bash
npm run doc
```

## Example
This example sets up a typical control flow. Press down keys on your QWERTY keyboard to see their coordinates logged in the console.

Press keys down with 'Shift' to sustain them (nothing triggered on physical release of the key) and press 'backquote' (the key next to the digit '1') to trigger the pending keyup callbacks when you please.

```typescript
import {Keyboard, type CoordinateKeyboardEvent} from 'isomorphic-qwerty'

const typingKeyboard = new Keyboard();

function typingKeydown(event: CoordinateKeyboardEvent) {
if (event.code === 'Backquote') {
typingKeyboard.deactivate();
function noKeyup() {}
return noKeyup;
}
const triggeringEvent = event;
console.log(`You pressed down ${event.code} which lies at coordinates ${event.coordinates}`);

function keyup() {
console.log(`You released ${triggeringEvent.code} which lies at coordinates ${triggeringEvent.coordinates}`);
}
return keyup;
}

typingKeyboard.addKeydownListener(typingKeydown);

window.addEventListener('keydown', typingKeyboard.keydown.bind(typingKeyboard));
window.addEventListener('keyup', typingKeyboard.keyup.bind(typingKeyboard));
```
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export class Keyboard {
}

/**
* Release keys sustained due to being pressed with 'Shift'.
* Release keys sustained due to being pressed down with 'Shift'.
*/
deactivate() {
this.log('Releasing all sustained and active keys');
Expand Down

0 comments on commit 01a868c

Please sign in to comment.