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 🙏

© 2024 – Pkg Stats / Ryan Hefner

kbhook

v1.0.19

Published

是一个用于监听和处理键盘快捷键的 JavaScript SDK。它允许你轻松定义自定义快捷键并为其分配回调函数

Downloads

3

Readme

schook SDK

kbhook 是一个用于监听和处理键盘快捷键的 JavaScript SDK。它允许你轻松定义自定义快捷键并为其分配回调函数。

安装

使用 npm 安装 kbhook

npm install kbhook

使用 yarn 安装 kbhook

yarn add kbhook

快速开始

以下是如何在您的项目中使用 kbhook 的简单示例:

const KBHook = require('kbhook');

const kbHook = new KBHook();

// 设置快捷键 Ctrl+Shift+L
kbHook.setKey('Ctrl+Shift+L', () => {
  console.log('Ctrl+Shift+L 快捷键被触发');
});

// 设置快捷键 Alt+A
kbHook.setKey('Alt+A', () => {
  console.log('Alt+A 快捷键被触发');
});

// 捕获 Ctrl+Q
kbHook.startCapture('Ctrl+Q', (err, key) => {
  err ? console.log('快捷键重复-Ctrl+Q: ', err) : console.log('key: ', key)
})

// 捕获 Ctrl+Alt+Q
kbHook.startCapture('Ctrl+Alt+Q', (err, key) => {
  err ? console.log('快捷键重复-Ctrl+Alt+Q: ', err) : console.log('key: ', key)
})

// 当不再需要快捷键功能时,清理资源
kbHook.dispose();

API 参考

setKey(keyStr, callback)
设置一个快捷键及其回调函数。

keyStr (String): 快捷键的字符串表示,例如 'Ctrl+Shift+L'。
callback (Function: (err: Error | null, ret?:string) => void): 当快捷键被触发时执行的回调函数。如果传入 null 将取消该快捷键的监听。
startSetMode(key, callback)
开始捕获指定快捷键的操作。

key (String): 指定要捕获的快捷键字符串,例如 'Ctrl+Shift+L'。
callback (Function): 一个回调函数,接收错误对象和消息字符串。
destroy()
清理资源并停止所有快捷键的监听。

注意事项

请确保你有适当的权限来安装和使用依赖的原生模块。在某些情况下,可能需要管理员权限来成功安装。

开源许可

此项目采用 MIT 许可证,您可以在项目的 LICENSE 文件中查看许可信息。

贡献

欢迎开源社区的贡献和意见。如果您想贡献代码,请遵循项目的贡献指南。