Skip to content

Commit

Permalink
fixed travis ci badge
Browse files Browse the repository at this point in the history
  • Loading branch information
bobinrinder committed Jul 18, 2021
1 parent 57bb98f commit a2c5b53
Showing 1 changed file with 46 additions and 32 deletions.
78 changes: 46 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# react-keyboard-input-hook [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Build Status](https://travis-ci.org/bobinrinder/react-keyboard-input-hook.svg?branch=master)](https://travis-ci.org/bobinrinder/react-keyboard-input-hook) [![Coverage Status](https://coveralls.io/repos/github/bobinrinder/react-keyboard-input-hook/badge.svg)](https://coveralls.io/github/bobinrinder/react-keyboard-input-hook) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/bobinrinder/react-keyboard-input-hook/pulls)
# react-keyboard-input-hook [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![Build Status](https://travis-ci.com/bobinrinder/react-keyboard-input-hook.svg?branch=master)](https://travis-ci.org/bobinrinder/react-keyboard-input-hook) [![Coverage Status](https://coveralls.io/repos/github/bobinrinder/react-keyboard-input-hook/badge.svg)](https://coveralls.io/github/bobinrinder/react-keyboard-input-hook) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/bobinrinder/react-keyboard-input-hook/pulls)

A [React Hook](https://reactjs.org/docs/hooks-intro.html) to easily work with keyboard inputs. This library was originally built for controlling input from a Fire TV remote but it is now flexible for any keyboard input that works with key codes.

Expand All @@ -21,13 +21,13 @@ import { useKeyUp, useKeyDown, useKeyCombo } from "react-keyboard-input-hook";
function App() {
// wrapping in useCallback is usually recommended
const handleKeyUp = ({ keyName }) => {
console.log('the ' + keyName + ' was just released!');
console.log("the " + keyName + " was just released!");
};
const handleKeyDown = ({ keyName }) => {
console.log('the ' + keyName + ' was just pressed down!');
console.log("the " + keyName + " was just pressed down!");
};
const handleKeyCombo = () => {
console.log('a combo of up and down arrow was just pressed!');
console.log("a combo of up and down arrow was just pressed!");
};

// only destructure what you need, callback is optional
Expand All @@ -38,9 +38,11 @@ function App() {

return (
<div>
<h1>Last pressed key code: {keyCode}</h1>
<h1>Last pressed key name: {keyName}</h1>
<h6>History of pressed keys: {keyCodeHistory.map(item => item + ", ")}</h6>
<h1>Last pressed key code: {keyCode}</h1>
<h1>Last pressed key name: {keyName}</h1>
<h6>
History of pressed keys: {keyCodeHistory.map((item) => item + ", ")}
</h6>
</div>
);
}
Expand All @@ -51,57 +53,69 @@ export default App;
## Reference

### useKeyUp
#### Parameters:

#### Parameters:

- **callback** (optional, default `null`):
Callback function that gets executed on every event.
Callback argument object:
Callback function that gets executed on every event.
Callback argument object:

```js
{
keyName, // string of pressed key
keyCode, // integer of pressed keyCode
e // event e.g. for e.PreventDefault()
{
keyName, // string of pressed key
keyCode, // integer of pressed keyCode
e; // event e.g. for e.PreventDefault()
}
```

- **whitelist** (optional, default `[]`):
Whitelist of keyboard keyCodes (integer array) that are relevant, all other keys will be ignored.
Note: Can only be used if `blacklist` paramater is an empty array.
Whitelist of keyboard keyCodes (integer array) that are relevant, all other keys will be ignored.
Note: Can only be used if `blacklist` paramater is an empty array.
- **blacklist** (optional, default `[]`):
Blacklist of keyboard keyCodes (integer array) that are irrelevant and therefore will be ignored.
Note: Can only be used if `whitelist` paramater is an empty array.
Blacklist of keyboard keyCodes (integer array) that are irrelevant and therefore will be ignored.
Note: Can only be used if `whitelist` paramater is an empty array.

#### Return Object:

#### Return Object:
```jsx
{
keyCode, // integer of last pressed keyCode
keyCodeHistory, // array of integers of recently pressed keyCodes
keyName, // string of last pressed key
keyNameHistory // array of strings of recently pressed keys
{
keyCode, // integer of last pressed keyCode
keyCodeHistory, // array of integers of recently pressed keyCodes
keyName, // string of last pressed key
keyNameHistory; // array of strings of recently pressed keys
}
```

### useKeyDown

Same as `useKeyUp`.

### useKeyCombo
#### Parameters:

#### Parameters:

- **keyCodes** (required):
Array of at least 2 integer key codes that make up the key down combination.
Array of at least 2 integer key codes that make up the key down combination.
- **callback** (required):
Callback function that gets executed once for each combo.
Callback argument object:
Callback function that gets executed once for each combo.
Callback argument object:

```js
{
keyName, // string of last pressed key of combo
keyCode, // integer of last pressed keyCode of combo
e // event e.g. for e.PreventDefault()
{
keyName, // string of last pressed key of combo
keyCode, // integer of last pressed keyCode of combo
e; // event e.g. for e.PreventDefault()
}
```

### useFireTvKeyUp

Same as `useKeyUp` but with `whitelist` parameter defaulting to Fire TV key codes only (8, 13, 37, 38, 39, 40, 179, 227, 228).

### useFireTvKeyDown

Same as `useKeyUp` but with `whitelist` parameter defaulting to Fire TV key codes only (8, 13, 37, 38, 39, 40, 179, 227, 228).

## License

MIT

0 comments on commit a2c5b53

Please sign in to comment.