npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@keekuun/keymaster-react

v0.5.0

Published

React 版 keymaster 键盘快捷键库(基于 Vite 与 TypeScript 的库模式构建)。

Readme

@keekuun/keymaster-react

🌐 语言

React 版 keymaster 键盘快捷键库,通过 Hook 帮助你在组件中优雅地绑定键盘快捷键。

特性

  • 使用 useKeyBinding 一行代码绑定快捷键
  • 支持组合快捷键(如 ctrl+sctrl+shift+z
  • 默认监听 windowkeydown 事件,使用简单
  • 作用域快捷键:支持在特定元素范围内绑定快捷键(scopedElement
  • 编辑器模式:自动处理编辑器场景的快捷键冲突
  • Electron 模式:适配 Electron 应用的特殊需求
  • TypeScript 完整类型提示

安装

npm install @keekuun/keymaster-react
# 或者
pnpm add @keekuun/keymaster-react

快速开始

import React from 'react';
import { useKeyBinding } from '@keekuun/keymaster-react';

function Editor() {
  useKeyBinding(
    'ctrl+s',
    () => {
      // 在这里执行保存逻辑,例如:调接口 / 更新本地状态
      console.log('保存成功');
    },
    { preventDefault: true }, // 阻止浏览器默认的保存页面行为
  );

  return <textarea placeholder="在这里输入内容,然后按 Ctrl+S 触发保存"></textarea>;
}

export default Editor;

高级功能

作用域快捷键

在特定元素范围内绑定快捷键,适用于编辑器、对话框等场景:

import { useScopedKeyBinding } from '@keekuun/keymaster-react';

const editorRef = useRef<HTMLTextAreaElement>(null);
useScopedKeyBinding(
  'ctrl+s',
  () => {
    saveContent();
  },
  editorRef,
);

编辑器模式

自动处理编辑器场景的快捷键冲突:

import { useEditorKeyBinding } from '@keekuun/keymaster-react';

const editorRef = useRef<HTMLTextAreaElement>(null);
useEditorKeyBinding(
  'ctrl+s',
  () => {
    saveCode();
  },
  editorRef.current,
);

Electron 模式

适配 Electron 应用:

import { useElectronKeyBinding } from '@keekuun/keymaster-react';

useElectronKeyBinding('ctrl+alt+r', () => {
  window.location.reload();
});

API 概览

useKeyBinding(shortcut, handler, options?)

  • shortcut: string
    快捷键字符串,例如 "ctrl+s""ctrl+shift+z"
  • handler: (event: KeyboardEvent) => void
    当捕获到匹配的快捷键时触发的回调。
  • options: KeymasterBindingOptions(可选)
    • preventDefault?: boolean 是否在触发后调用 event.preventDefault()
    • stopPropagation?: boolean 是否在触发后调用 event.stopPropagation()
    • scopedElement?: HTMLElement | null 作用域元素,快捷键仅在元素内生效
    • editorMode?: boolean 编辑器模式,自动处理快捷键冲突
    • electronMode?: boolean Electron 模式,适配 Electron 应用

registerKeyBinding(shortcut, handler, options?)

底层的通用注册函数(非 Hook),返回一个取消绑定的函数:

import { registerKeyBinding } from '@keekuun/keymaster-react';

const dispose = registerKeyBinding(
  'ctrl+s',
  (event) => {
    console.log('保存成功');
  },
  { preventDefault: true },
);

// 需要时手动解绑
dispose();

文档与示例

更多交互 Demo、使用场景与设计建议请访问文档站点: