shortcut-key-sensor
v1.1.0
Published
Shortcut key sensor to reactjs
Downloads
5
Maintainers
Readme
shortcut-key-sensor
Install
npm install --save shortcut-key-sensor
Usage
import React, { Component } from 'react';
import ShortcutKeySensor from 'shortcut-key-sensor';
const Example = () => {
const actions = {
'CTRL+A': () => alert('Clicked in CTRL+A'),
'CTRL+SHIFT+A': () => alert('Clicked in CTRL+SHIFT+A'),
'SHIFT+A': () => alert('Clicked in SHIFT+A'),
'A': () => alert('Clicked in A'),
}
return (
<ShortcutKeySensor actions={actions}>
<h1>Example ShortcutKeySensor</h1>
</ShortcutKeySensor>
);
}
Usage Hook
import React, { Component } from 'react';
import { useShortcutKeySensor } from 'shortcut-key-sensor';
const ExampleHook = () => {
useShortcutKeySensor('CTRL+A', (event) => alert('Clicked in CTRL+A'));
useShortcutKeySensor('CTRL+SHIFT+A', (event) => alert('Clicked in CTRL+SHIFT+A'));
useShortcutKeySensor('SHIFT+A', (event) => alert('Clicked in SHIFT+A'));
useShortcutKeySensor('A', (event) => alert('Clicked in A'));
return <h1>Example useShortcutKeySensor</h1>;
}