https://github.com/yukiniro/toukey
👻 Toukey is a simple and efficient keyboard events library.
https://github.com/yukiniro/toukey
events hotkey javascript keyboard keyboardevent keydown keyup shortcuts toukey
Last synced: about 2 months ago
JSON representation
👻 Toukey is a simple and efficient keyboard events library.
- Host: GitHub
- URL: https://github.com/yukiniro/toukey
- Owner: Yukiniro
- License: mit
- Created: 2022-02-19T15:58:23.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-03-24T13:43:55.000Z (about 2 months ago)
- Last Synced: 2025-03-26T03:35:08.432Z (about 2 months ago)
- Topics: events, hotkey, javascript, keyboard, keyboardevent, keydown, keyup, shortcuts, toukey
- Language: TypeScript
- Homepage: toukey.vercel.app
- Size: 1.6 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README-zh.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Toukey
`Toukey` 是一个简单、高效的键盘事件库。这里是 [toukey](https://toukey.vercel.app/) 的文档网站 [toukey's]。
## 安装
```shell
npm i toukey
```## 使用
### 浏览器
你可以在浏览器中通过 [UNPKG](https://unpkg.com/browse/toukey/dist/) | [jsDelivr](https://www.jsdelivr.com/package/npm/toukey) 这些 `cdn` 进行使用。
```javascript
toukey.subscribe('space', function() {
console.log('space');
});```
### React
在 react 也很容易。
```javascript
import { useEffect } from "react";
import { subscribe } from "toukey";function App() {
useEffect(() => {
return subscribe("scope", () => {
console.log("scope");
});
});return
hello world;
}
```这里有一个基于 `toukey` 制作的 react hook 的库 [react-toukey-hook](https://github.com/Yukiniro/react-toukey-hook)。
### 基本使用
```javascript
import * as Toukey from "toukey";const handler = () => console.log("handler");
// subscribe
Toukey.on("scope", handler);// unsubscribe
Toukey.off("scope", handler);
``````javascript
import { subscribe } from "toukey";const unsubsribe = subscribe("scope", () => {
console.log("scope");
});
```