jQuery Hotkeys lets you watch for keyboard events anywhere in your code supporting almost any key combination.

Overview

jQuery.Hotkeys Build Status

#About jQuery Hotkeys is a plug-in that lets you easily add and remove handlers for keyboard events anywhere in your code supporting almost any key combination.

This plugin is based off of the plugin by Tzury Bar Yochay: jQuery.hotkeys

The syntax is as follows:

$(expression).bind(types, keys, handler);
$(expression).unbind(types, handler);

$(document).bind('keydown', 'ctrl+a', fn);

// e.g. replace '$' sign with 'EUR'
$('input.foo').bind('keyup', '$', function(){
  this.value = this.value.replace('$', 'EUR');
});

Syntax when wanting to use jQuery's on()/off methods:

$(expression).on(types, null, keys, handler);
$(expression).off(types, handler);

$(document).on('keydown', null, 'ctrl+a', fn);

// e.g. replace '$' sign with 'EUR'
$('input.foo').on('keyup', null, '$', function(){
  this.value = this.value.replace('$', 'EUR');
});     

Example

Example

Event Types

Supported types are 'keydown', 'keyup' and 'keypress'

jQuery Compatibility

Works with jQuery 1.4.2 and newer.

It is known to be working with all the major browsers on all available platforms (Win/Mac/Linux)

  • IE 6/7/8+
  • FF 1.5/2/3+
  • Opera-9+
  • Safari-3+
  • Chrome-0.2+

Browserify Compatibility

If you want to include this module in a Browserified project, just add it to node_modules and require it.

require('jquery.javascript');

This will work if jQuery is global (ex. served from a CDN). If it's not, you need to shim it:

{
  "browserify-shim": {
    "jquery": "global:jQuery"
  }
}

Notes

Modifiers are not case sensitive (Ctrl == ctrl == cTRL)

If you want to use more than one modifier (e.g. alt+ctrl+z) you should define them by an alphabetical order e.g. alt+ctrl+shift

Hotkeys aren't tracked if you're inside of an input element (unless you explicitly bind the hotkey directly to the input). This helps to avoid conflict with normal user typing.

You can use namespacing by adding a suffix to the event type (e.g. keyup.toggle)

Hotkeys within inputs

Hotkeys aren't tracked if the user is focused within an input element or any element that has contenteditable="true" unless you bind the hotkey directly to the element. This helps to avoid conflict with normal user typing. If you don't want this, you can change the booleans of the following to suit:

  • jQuery.hotkeys.options.filterInputAcceptingElements
  • jQuery.hotkeys.options.filterContentEditable
  • jQuery.hotkeys.options.filterTextInputs (deprecated, will be removed in a later version)

Meta and Hyper Keys

Meta and hyper keys don't register on keyup in any browser tested.

Chrome 33.0.1750.117

Meta key registers on keydown event. Hyper key registers on keydown event.

Firefox 27.0.1 and Safari 7.0.1

Meta key registers on keydown and keypress events. Hyper key registers on keydown and keypress events.

Opera 19.0

Meta key doesn't register at all :( Hyper key registers on keydown and keypress events.

TL;DR

Bind to keydown event for meta and hyper keys, but meta key does not work in Opera ;)

Addendum

Firefox is the most liberal one in the manner of letting you capture all short-cuts even those that are built-in in the browser such as Ctrl-t for new tab, or Ctrl-a for selecting all text. You can always bubble them up to the browser by returning true in your handler.

Others, (IE) either let you handle built-in short-cuts, but will add their functionality after your code has executed. Or (Opera/Safari) will not pass those events to the DOM at all.

So, if you bind Ctrl-Q or Alt-F4 and your Safari/Opera window is closed don't be surprised.

Comments
  • Added bower.json file

    Added bower.json file

    I'm not sure about the Licence or different things, but since the issues are not enabled for this project I just created a PR with the simplest one.. it is super useful and it looks like the original project is a bit dead..

    opened by lipis 11
  • Remove shiftnums as they are incompatible with non-US keyboards

    Remove shiftnums as they are incompatible with non-US keyboards

    The usage of shiftNums to allow bindings such as $ to indicate Shift+4 don't work on non-US keyboard layouts.

    French keyboard 38565_xlargenss_ndo4211

    As you can see, the $ key is a dedicated key next to return. Binding to $ won't actually trigger when you press the $ key, as it has keycode 220.

    This issue with jquery.hotkeys was noted over two years ago https://github.com/ccampbell/mousetrap/issues/2#issuecomment-6818461, but since this repo doesn't have issues, it went unreported.

    Removing this feature is not a complete fix for this problem, but I wanted to raise the issue in the form of a pull request so it's documented that this is a problem with this jQuery plugin.

    opened by lazd 7
  • Fix keypress on special keys and keydown/keyup on characters

    Fix keypress on special keys and keydown/keyup on characters

    This fix allows to handle special keys with keypress event (special keys can trigger all kinds of events with valid keyCode). It also fixes usage of invalid character codes on keydown/keyup events (valid charCode available only with keypress events, though we have to use which property because IE passes character codes in keyCode)

    Reference used: http://www.quirksmode.org/js/keys.html

    opened by YuppY 6
  • Update dependencies, add missing grunt-contrib-watch dependency

    Update dependencies, add missing grunt-contrib-watch dependency

    • Use caret instead of ~ for safer dependency management
      • This drops support for running the build on Node 0.8
    • Update SpecRunner.html to have new links for ES5 shim
    opened by lazd 5
  • Disable hotkeys in password inputs

    Disable hotkeys in password inputs

    A small patch to disable keyboard shortcuts for password fields, unless you've specifically bound to them. Previously only inputs of type text were being ignored.

    Great plugin!

    Thanks, -Nick

    opened by nicholasbs 3
  • extend handler arguments to include key name

    extend handler arguments to include key name

    usage example

    // handler is using extra argument: key name
    function handler(event, key) {
       if ( key == 'ctrl+a') {
          console.log('found by key name');
       }
    }
    $(document).bind('keydown', 'ctrl+a ctrl+b ctrl+c', handler);
    
    opened by Andrei-Pozolotin 2
  • Added support and test cases for additional key mappings [ ] \ ; ' , . /

    Added support and test cases for additional key mappings [ ] \ ; ' , . /

    I've added support and a demo (test-static-01.html) that add support for additional characters [ ] \ ; ' , . / It also addresses a key mapping issue where some keyboards (like mine) map - and = to different key codes.

    opened by kwilliaa 2
  • Fix for jQuery hotkeys being triggered in password fields.

    Fix for jQuery hotkeys being triggered in password fields.

    If you're in an input box of the password type, your hotkeys will still be triggered, unlike for normal input fields, because it only checks for event.target.type === "text". I've fixed that in this fork by also checking for "password", based on the details listed on Google Code.

    This is my first GitHub pull request. And my first contribution to another open source project. I think I did everything right (not that there was much to it).

    opened by jschuur 2
  • Making filtering text inputs easy / simple again

    Making filtering text inputs easy / simple again

    This is de-facto a revert of the pull request "#54 from abolishme/patch-1" (see the discussion there) and follow-up commits, while also clarifying how the original code was possibly meant and bringing back some "reasonable defaults".

    Plus fixing related (structure) typos in the README file.

    opened by pbodnar 6
Owner
John Resig
Chief Architect at @Khan
John Resig
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.

KeyboardJS KeyboardJS is a library for use in the browser (node.js compatible). It Allows developers to easily setup key bindings. Use key combos to s

Robert Hurst 2k Dec 30, 2022
⌨ Awesome handling of keyboard events

No Longer Actively Maintained If someone would like to take over maintainence, feel free to get in touch (@keithamus on twitter). I'll happily transfe

Keith Cirkel 1.2k Dec 6, 2022
Utility to show key presses in your application

Utility to show key presses in your application

Siddharth Kshetrapal 56 Jul 16, 2022
Simple library for handling keyboard shortcuts in Javascript

Mousetrap Mousetrap is a simple library for handling keyboard shortcuts in Javascript. It is licensed under the Apache 2.0 license. It is around 2kb m

Craig Campbell 11.3k Jan 3, 2023
A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.

keymaster.js Keymaster is a simple micro-library for defining and dispatching keyboard shortcuts in web applications. It has no dependencies. It’s a w

Thomas Fuchs 6.5k Jan 4, 2023
A keyboard input capturing utility in which any key can be a modifier key.

Keypress Version 2.1.5 Keypress is a robust keyboard input capturing Javascript utility focused on input for games. For details and documentation, ple

David Mauro 3.2k Dec 28, 2022
OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.

OpenUI5. Build Once. Run on any device. What is it? OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on al

SAP 2.7k Dec 31, 2022
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.

KeyboardJS KeyboardJS is a library for use in the browser (node.js compatible). It Allows developers to easily setup key bindings. Use key combos to s

Robert Hurst 2k Dec 30, 2022
A JavaScript library for binding keyboard combos without the pain of key codes and key combo conflicts.

KeyboardJS KeyboardJS is a library for use in the browser (node.js compatible). It Allows developers to easily setup key bindings. Use key combos to s

Robert Hurst 2k Dec 30, 2022
Remote Keyboard Tutoring System is a web-based system that can be attached to any keyboard synthesizer through a MIDI connector.

The Remote Keyboard Tutoring System is a web-based system that can be attached to any (electronic) keyboard synthesizer through a MIDI connector. Once our system is connected to the keyboard, the user can interactively learn, play or teach in combination with the web application that we provide.

Department of Computer Engineering, University of Peradeniya 3 Nov 15, 2022
A jQuery plugin that lets you attach callbacks to useful image loading events.

waitForImages Copyright (c) 2011-2018 Alexander Dickson @alexdickson Licensed under the MIT licenses. http://alexanderdickson.com Donate! Overview Pro

Alexander Dickson 1.3k Dec 28, 2022
A jQuery Single/Multi Select plugin which can be used on almost any device

jquery.sumoselect jquery.sumoselect.js - A beautiful cross device Single/Multi Select jQuery Select plugin. A jQuery plugin that progressively enhance

Hemant Negi 537 Dec 7, 2022
Subscribe to rss feeds from anywhere, receive notifications from anywhere.

INK RSS 管理订阅,接收通知 示例网页 · 示例群组 · 报告Bug 介绍 特点 项目背景 TODO 注意事项 部署 额外附赠 使用建议 调查 贡献 作者 协议 介绍 INK RSS 提供及时且多样的 rss 通知服务,借助现有的接口你可以在任意位置订阅,并使用任意方式接收通知,并且所有服务均

null 253 Dec 28, 2022
A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

Devang Joshi 1 Mar 1, 2021
Bookmate - Watch changes in Chrome bookmarks, and use bookmarks as an append-only key-value store via an fs-like API.

?? Bookmate An append-only key-value store built on Chrome bookmarks, plus an asychronous stream of Bookmark changes. For NodeJS Actual production exa

Cris 6 Nov 8, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A ~2kb hotkeys library for solid that adds only 2 event listeners.

Solid Hotkeys - Cmd+S+H Solid Hotkeys is the easiest way to add hotkeys to your application. Built for and with Solid. Motivation You gotta have hotke

Alek Angelov 12 Aug 1, 2022