Giter Club home page Giter Club logo

codad5 / keybinder Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 0.0 216 KB

This is a Javascript library that helps with listening to browser Keyboard changes, and also helps in managing keyboard shortcuts in the browser. browser keyboard controller

Home Page: https://codad5.github.io/keybinder

License: MIT License

HTML 18.88% TypeScript 50.77% JavaScript 30.35%
dom keybindings keyboard keyboard-events javascript shortcut-fusion shortcuts-app typescript

keybinder's Introduction

Key Bonder/Binder

Watch the video

This is a javascript library for frontend development (both vallina and frameworks) that helps with keyboard binding / combinations .

This currently supports most keys in windows OS you can visit the Home page to check the key code for your machine

Requirement

  • Your script need to be running on a web server, for development you could use,
    • live server extension is vscode
    • node npx server by running npx serve
    • to avoid errors like KeyBinder Cors error

How to use

Install and Import

Using Vallina javascript

<script src="https://codad5.github.io/keybinder/lib/keybinder.js"></script>

Using a framework

  • Install
npm i domkeybinder
  • Import
import KeyBinder from 'domkeybinder'

Initialize your controller object

  • Define your keyboard Controller
const keyController = new KeyBinder({
    default_listener: 'keyup', // can be keydown, keypress
    element: window, // can be any element or window eg `docmuent.querySelector('.myeditor')
    // case_sensitive:true, // this is if you want to make the listener case sensitive
    allow_default: true // this is set to default of false and prevents any default keyboard action
})
  • Add your listener

For easier and better coding experience it best to create a sub function like this

const ListenToKey = (key, ...data) => keyController.ListenToKey(key, ...data)

Then you can add listeners like this

ListenToKey('B+G', () => {
    //your code...
})

ListenToKey('shift+c', () => {
    //your code...
})

OR this

keyController.ListenToKey('enter', (data) => {
    //your code...
})

keyController.ListenToKey('ctrl+space', () => {
    //your code...
})

Diffrent Combination one action

This is if you want to one action(callback), tied to different combination

ListenToKey('ctrl+space', 'ctrl+m', () => {
    alert(`your called ${data.combination}`)
    document.querySelector('#scdiv').innerHTML += 'Do you mean Ctrl+c? try Ctrl+c'
})

Avaliable methods

method Description
ListenToKey Add new Listener
getCombinations Get all avaliable combinations
clear Remove all avaliable combinations
restore Restore all previous avaliable combinations

Check Our Test Website to see the avaliable key commands for

Key listener - Command
Control ctrl
Shift Shift
Alt Alt
A A
A...Z A...Z
A...Z A...Z
> arrowup
1 !
1...9 1...9
f1...f9 f1...f9
Windows - Home Buttom meta
Listen to any other key ***

Todos

  • Accept Your pull request ✔

This is built by Codad5 and ptbysr with ❤ and ⚡

keybinder's People

Contributors

codad5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

keybinder's Issues

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.