GithubHelp home page GithubHelp logo

keyboarder's Introduction

introduction

网页也可以像 vim 编辑器一样的支持快捷键

keyboader 封装了对复杂按键的监听,从而让我们的网页事件更丰富

quick start

yarn add keyboader
import addKeyListener from 'keyboarder'

addKeyListener({
  a: () => alert('用户按下了 a 键'),
  abc: () => alert('用户顺序按下了 abc 键')
})

复杂按键配置

按键配置:

addKeyListener({
  a: () => {
    alert("a");
    // 由于有 ab 的存在,因此会延迟执行
  },
  ab: () => {
    alert("ab");
    // 没有后续待匹配的,则直接执行
  },
  // 复杂按键,用 | 分割
  "m-a|m-b": () => {
    // 全部复杂按键的
    alert("用户按住meta(即mac下的command), 并顺序按了 a、b");
  },
  "m-a|b": () => {
    // 首字母复杂按键的
    alert("用户按住meta,并按下a,之后松开meta,并按下 b");
  },
  "m-c-c|b": () => {
    // 多复杂按键的 按照 meta alt control shift 的顺序,如 m-a-c-s-v 表示按下了 meta、alt、control、shift 并按了 v 键。注:mac 下实际 alt(option) 用不上,因为会改变字符
    alert("用户按住 meta 和 control 键,并按下了 c,之后松开,并按下了 b");
  },
  "m-c-c|m-c-v": () => {
    // 全部多复杂按键
    alert("m-c-c|m-c-v");
  },
  "a|b", // 特殊规则:按过 cmd 之后,弹起,再输入 ab
  "|a", // 特殊规则:针对按过 meta 并弹起,再按 a
});

其他配置

addKeyListener(orders, 2000, command => {
  alert(`用户当前命令为: ${command}`)
})

2、3 参可选,一个是设置超时时间,默认 1500,一个设置回调,显示当前的命令

esc 键能清空之前的命令

keyboarder's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.