A keyboard input capturing utility in which any key can be a modifier key.

Overview

Keypress

Version 2.1.5

Keypress is a robust keyboard input capturing Javascript utility focused on input for games. For details and documentation, please visit http://dmauro.github.io/Keypress/

If you're using Keypress with Meteor, see the Meteor notes.

Copyright 2016 David Mauro
released under the Apache License, version 2.0

What's new

2.1.5

2.1.4

2.1.3

2.1.2

  • Added some simple jQuery proofing so you can pass in the result of a jQuery selector into the Listener's constructor. Thanks to mallocator for the request. Issue #89
  • Changed the default behavior of how sequence combos behavior. Most people probably would have considered this a bug, so I'm not considering this API breaking. Thanks to ronnyek for pointing the problem out in Issue #68.
  • Bower file cleaned up thanks to kkirsche. Pull request #97
  • Keys in FF/Gecko - and = fixed thanks to deanputney. Pull request #95

2.1.1

2.1.0

2.0.3

  • Fixed a bug unregistering combos using arrays of keys
  • Added ie8 compatibility shim. Thanks to barrkel. Issue #41
  • Fixed a bug targetting the semicolon key in Firefox. Thanks to mikekuehn.
  • Added commonJS module support. Issue #45

2.0.2

  • Fixed a bug that prevented combos from unregistering, and updated the docs for how to unregister properly. Thanks to pelly and g00fy-. Issue # 34.
  • Added AMD support. Issue #37.

2.0.1

  • Fixed a big ole bug with meta/cmd combos. Thanks to lexey111. Issue #29.
  • Fixed a bug with the Windows key being released on Windows systems. Issue #27.

2.0.0

  • Keypress now has a listener class that must be instantiated. The functions that were previously in the global window.keypress object are now public methods of the window.keypress.Listener class.
  • Each instance of a Keypress listener can be bound to a DOM element by passing in the element to the listener's constructor.
  • Combos now default to being ordered (the property is now called is_unordered and is false by default).
  • Combos' handlers preventDefault unless the handler returns true.
  • The "combo" public method is now called "simple_combo".
  • The basic combo helpers for simple, counting and sequence combos no longer have a third prevent_default optional parameter.
  • Debugging console logs can be enabled by setting keypress.debug to true.
  • All key event callbacks send a third argument specifying whether the event is firing again automatically because the key has remained pressed down.

1.0.9

  • Fix escape key bug. Issue #17.
  • Fix unregister bug. Issue #24.

1.0.8

  • Ensure that on_release is called for all combos, not just counting combos.
  • Fix bug that was causing is_ordered to be ignored.
  • Fixed an edge case for a counting combo's count not being reset.
  • Improve how key events are bound

1.0.7

  • Fixed combo matching to prevent performance issues as more keys are pressed.

1.0.6

  • Fixed a bug with exclusive combos not properly excluding each other in some cases.
  • Feature added to allow for combos that do not fire if unrelated keys are also pressed ("is_solitary" boolean).

TODO

  • Put negative edge in sequences.
  • See if we can do away with keyup_fired and count properties.
Comments
  • "meta /" doesn't work on windows

    keypress.combo('meta /', function(event) {
      // show help dialog ...
    });
    

    The problem on windows is if we holding "ctrl" then press down "/", it won't work. But reversely it works.

    bug 
    opened by xiaoli 9
  • Caps Lock remains in the `_keys_down` array.

    Caps Lock remains in the `_keys_down` array.

    I've only tested on a Mac, however, the caps indicator remains in the _keys_down array when turned on. This results in is_solitary key combinations not being able to be triggered since caps is down.

    This happens at the OS level, as you can see by triggering Caps Lock on this page: http://www.asquare.net/javascript/tests/KeyCode.html – There is a keyDown event, but no keyUp event until the key is pressed again.

    enhancement 
    opened by beauwest 8
  • F1-F12 keys

    F1-F12 keys

    I've tried to use f4, f_2, etc. It does not recognize it. With monkey patching i've added those keys into _keycode_dictionary. It seems, that it worked.

    If it not my mistake, please add this functionality.

    Also have bugs with decimal at numpad detection after a switching keyboard layout from english to russian.

    When i use hotkey num_7, i.e., it fires when i use non-existant hotkey, i.e. ctrl num_7.

    enhancement 
    opened by night-crawler 8
  • stop_listening() doesn't seem to work as intended

    stop_listening() doesn't seem to work as intended

    When binding stop_listening() to the user being focused on a text field, it should prevent prevent capture, but something doesn't prevent the listener from listening.

    opened by justinguk 6
  • Restricting input to specific DOM elements

    Restricting input to specific DOM elements

    Is there a way to specify the root DOM element for which all shortcuts apply? There are cases where the same shortcut can trigger different callbacks depending on which DOM element is focused for the keyboard input. Conversely, if there's a way we can also namespace the shortcut definitions, that will also solve this issue.

    enhancement 
    opened by ashwinr 6
  • if i press cmd first, other meta keys can not be captured.

    if i press cmd first, other meta keys can not be captured.

    say, if i press in this order: ctrl + option + cmd it would work fine.

    but if i press in this order: cmd + ctrl + option (or other combination, only if i press cmd first) it would not work

    enhancement 
    opened by zhuangya 6
  • Package name on Bower?

    Package name on Bower?

    As bower register gives back Duplicated package, I found this package:

    itg_twig.js 
    A keyboard input capturing utility in which any key can be a modifier key.
    
    dmauro  9 months ago    8 days ago  41  264
    

    I suppose we just use keypress or Keypress. The current one looks strange.

    opened by tiye 6
  • keypres inbetween time control

    keypres inbetween time control

    i dunno where to ask thats why raised this as an issue sorry..below is the seq i am planning to use

    keypress.sequence_combo("backspace backspace", function() { // lives = 120; alert("You've pressed this bkspc."); }, true);

    the issue i am facing is..

    when i press backspace very contionus for 2 times it works as expected but when i delay the press it does not work,,

    is there a way where we can control this intermediate keypress control

    Regards Venkat.S

    enhancement 
    opened by venkat330 5
  • IE8 compatibility

    IE8 compatibility

    I have this warning on IE8 'keyCode' has null value or is not an object at keypress.js line 10 char 370 (original avert is in french)

    in IE, it seems that onkeydown does not pass event in callback function ( e = 'undefined') at line 488

    opened by arno14 5
  • ctrl+s doesn't work any more

    ctrl+s doesn't work any more

    {
          "keys": "meta s",
          "is_exclusive": true,
          "is_ordered": true,
          "on_keydown": function(e) {
            // it don't trigger ?
            e.preventDefault();
            return false;
          },
          "on_keyup": function(e) {
           // it's ok
            e.preventDefault();
            return false;
          }
        }
    

    when i use ctrl+s under windows , "on_keydown" function doesn't run. But it work well under mac.

    bug 
    opened by xwartz 4
  • Right Alt triggers Left Ctrl in Windows on Polish keyboard

    Right Alt triggers Left Ctrl in Windows on Polish keyboard

    We received reports on the mis-triggered events of Right Alt key when using some non-US keyboard, for exmaple, Germen, Polish. After we look into the details, we found that Right Alt key also tirggers Left Ctrl key, whose keyCode is 17 with keyIdentifier of Control.

    The bug can be reproduced on Windows 7 Chrome, Polish programmer keyboard, pressing Right Alt.

    There's related issue on StackOverflow: http://stackoverflow.com/questions/7090898/right-alt-key-also-triggers-windows-message-for-left-control-key

    It's probably a bug of Windows. But in Keypress people may also encounter this problem.

    opened by tiye 4
  • Providing an

    Providing an "on_keydown" handler shouldn't stop the key from working inside inputs.

    I created a simple example:

    https://jsfiddle.net/qs4v9mua/

    If you try to use the "delete" key to remove characters from the input, it does nothing (unless you hold it down). However, if you use the "backspace" key, it works.

    The only difference between the two configuration is the fact that the "on_keydown" handler is passed. How do I fix this so the configuration doesn't interfere with inputs?

    opened by Giwayume 0
  • keycodes

    keycodes

    Hello,

    I couldn't find the key codes for play/pause, next and previous so I merged _keycode_dictionary with the keys found on https://github.com/wesbos/keycodes/blob/gh-pages/scripts.js

    I don't know if that's something you would want to do in the library but that's how I use it so I figured I would leave a note here.

      //Modified with key codes from https://github.com/wesbos/keycodes
      _keycode_dictionary = {
          0: 'That key has no keycode',
          3: 'break',
          8: 'backspace / delete',
          9: 'tab',
          12: 'clear',
          13: 'enter',
          16: 'shift',
          17: 'ctrl',
          18: 'alt',
          19: 'pause/break',
          20: 'caps lock',
          21: 'hangul',
          25: 'hanja',
          27: 'escape',
          28: 'conversion',
          29: 'non-conversion',
          32: 'spacebar',
          33: 'page up',
          34: 'page down',
          35: 'end',
          36: 'home',
          37: 'left arrow',
          38: 'up arrow',
          39: 'right arrow',
          40: 'down arrow',
          41: 'select',
          42: 'print',
          43: 'execute',
          44: 'Print Screen',
          45: 'insert',
          46: 'delete',
          47: 'help',
          48: '0',
          49: '1',
          50: '2',
          51: '3',
          52: '4',
          53: '5',
          54: '6',
          55: '7',
          56: '8',
          57: '9',
          58: ':',
          59: 'semicolon (firefox), equals',
          60: '<',
          61: 'equals (firefox)',
          63: 'ß',
          64: '@ (firefox)',
          65: 'a',
          66: 'b',
          67: 'c',
          68: 'd',
          69: 'e',
          70: 'f',
          71: 'g',
          72: 'h',
          73: 'i',
          74: 'j',
          75: 'k',
          76: 'l',
          77: 'm',
          78: 'n',
          79: 'o',
          80: 'p',
          81: 'q',
          82: 'r',
          83: 's',
          84: 't',
          85: 'u',
          86: 'v',
          87: 'w',
          88: 'x',
          89: 'y',
          90: 'z',
          91: 'Windows Key / Left ⌘ / Chromebook Search key',
          92: 'right window key',
          93: 'Windows Menu / Right ⌘',
          95: 'sleep',
          96: 'numpad 0',
          97: 'numpad 1',
          98: 'numpad 2',
          99: 'numpad 3',
          100: 'numpad 4',
          101: 'numpad 5',
          102: 'numpad 6',
          103: 'numpad 7',
          104: 'numpad 8',
          105: 'numpad 9',
          106: 'multiply',
          107: 'add',
          108: 'numpad period (firefox)',
          109: 'subtract',
          110: 'decimal point',
          111: 'divide',
          112: 'f1',
          113: 'f2',
          114: 'f3',
          115: 'f4',
          116: 'f5',
          117: 'f6',
          118: 'f7',
          119: 'f8',
          120: 'f9',
          121: 'f10',
          122: 'f11',
          123: 'f12',
          124: 'f13',
          125: 'f14',
          126: 'f15',
          127: 'f16',
          128: 'f17',
          129: 'f18',
          130: 'f19',
          131: 'f20',
          132: 'f21',
          133: 'f22',
          134: 'f23',
          135: 'f24',
          144: 'num lock',
          145: 'scroll lock',
          160: '^',
          161: '!',
          162: '؛ (arabic semicolon)',
          163: '#',
          164: '$',
          165: 'ù',
          166: 'page backward',
          167: 'page forward',
          168: 'refresh',
          169: 'closing paren (AZERTY)',
          170: '*',
          171: '~ + * key',
          172: 'home key',
          173: 'minus (firefox), mute/unmute',
          174: 'decrease volume level',
          175: 'increase volume level',
          176: 'next',
          177: 'previous',
          178: 'stop',
          179: 'play/pause',
          180: 'e-mail',
          181: 'mute/unmute (firefox)',
          182: 'decrease volume level (firefox)',
          183: 'increase volume level (firefox)',
          186: 'semi-colon / ñ',
          187: 'equal sign',
          188: 'comma',
          189: 'dash',
          190: 'period',
          191: 'forward slash / ç',
          192: 'grave accent / ñ / æ / ö',
          193: '?, / or °',
          194: 'numpad period (chrome)',
          219: 'open bracket',
          220: 'back slash',
          221: 'close bracket / å',
          222: 'single quote / ø / ä',
          223: '`',
          224: 'left or right ⌘ key (firefox)',
          225: 'altgr',
          226: '< /git >, left back slash',
          230: 'GNOME Compose Key',
          231: 'ç',
          233: 'XF86Forward',
          234: 'XF86Back',
          235: 'non-conversion',
          240: 'alphanumeric',
          242: 'hiragana/katakana',
          243: 'half-width/full-width',
          244: 'kanji',
          251: 'unlock trackpad (Chrome/Edge)',
          255: 'toggle touchpad',
      };
    
    
    
    opened by jhordies 1
  • Blocked by EasyPrivacy

    Blocked by EasyPrivacy

    Technically not an issue with Keypress.js, but nonetheless makes it harder to use:

    EasyPrivacy (https://easylist.to/), which is a very common adblocking/content-blocking list, contains a filter that blocks any script named Keypress.js (/keypress.js$script). You can, of course, evade this by renaming the script to something else, but it might be worth reaching out to them to see if they are deliberately blocking your script (which would be strange, since it's just a library and doesn't do anything malicious on it's own) and if they could remove or tweak that filter.

    opened by nathanielhudson 1
  • ALT CTRL 1 works, but ALT 1 and CTRL 1 do not.

    ALT CTRL 1 works, but ALT 1 and CTRL 1 do not.

    This is just one example. I'm having the issue with a number of keys, like other numbers and "K".

    I am NOT using the number keypad.

    I am using prevent_repeat, is_unordered, is_exclusive, is_solitary, and the "on_keydown" function. is_exclusive is strange... for instance, on CTRL1, if I use prevent_default, I get nothing. If I don't use prevent_default, it changes to the first tab (the default use of CTRL1).

    The debugger shows that they are registered: image

    opened by EdwardGioja 5
  • location support?

    location support?

    Hi,

    I just discovered this is available now. Any chance it could be integrated into the API? That would be amazing. I will try and get it directly from the event and see what happens, but it'd be awesome if it were directly integrated.

    https://www.w3.org/TR/DOM-Level-3-Events/#dom-keyboardevent-location

    opened by yanfali 0
Releases(2.1.5)
  • 2.1.5(Mar 5, 2018)

  • 2.1.4(Apr 2, 2016)

  • 2.1.3(Aug 22, 2015)

  • 2.1.2(Aug 16, 2015)

    • Added some simple jQuery proofing so you can pass in the result of a jQuery selector into the Listener's constructor. Thanks to mallocator for the request. Issue #89
    • Changed the default behavior of how sequence combos behavior. Most people probably would have considered this a bug, so I'm not considering this API breaking. Thanks to ronnyek for pointing the problem out in Issue #68.
    • Bower file cleaned up thanks to kkirsche. Pull request #97
    • Keys in FF/Gecko - and = fixed thanks to deanputney. Pull request #95
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Nov 9, 2014)

  • 2.0.3(Jul 13, 2014)

  • 2.0.2(May 4, 2014)

    • Fixed a bug that prevented combos from unregistering, and updated the docs for how to unregister properly. Thanks to pelly and g00fy-.
    • Added AMD support
    Source code(tar.gz)
    Source code(zip)
  • 2.0.1(Feb 5, 2014)

  • 2.0(Feb 5, 2014)

    • Keypress now has a listener class that must be instantiated. The functions that were previously in the global window.keypress object are now public methods of the window.keypress.Listener class.
    • Each instance of a Keypress listener can be bound to a DOM element by passing in the element to the listener's constructor.
    • Combos now default to being ordered (the property is now called is_unordered and is false by default).
    • Combos' handlers preventDefault unless the handler returns true.
    • The "combo" public method is now called "simple_combo".
    • The basic combo helpers for simple, counting and sequence combos no longer have a third prevent_default optional parameter.
    • Debugging console logs can be enabled by setting keypress.debug to true.
    • All key event callbacks send a third argument specifying whether the event is firing again automatically because the key has remained pressed down.
    Source code(tar.gz)
    Source code(zip)
jQuery Hotkeys lets you watch for keyboard events anywhere in your code supporting almost any key combination.

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

John Resig 2.6k Jan 2, 2023
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
⌨ 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
➷ A robust Javascript library for capturing keyboard input. It has no dependencies.

Hotkeys HotKeys.js is an input capture library with some very special features, it is easy to pick up and use, has a reasonable footprint (~3kb) (gzip

小弟调调™ 5.7k Jan 4, 2023
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
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 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
jQuery Hotkeys lets you watch for keyboard events anywhere in your code supporting almost any key combination.

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

John Resig 2.6k Jan 2, 2023
Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

Use plain functions as modifiers. Polyfill for RFC: 757 | Default Modifier Manager

null 7 Jan 14, 2022
Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Ian VanSchooten 4 Sep 29, 2022
Smooth subdivision surface modifier for use with three.js BufferGeometry.

Three Subdivide This modifier uses the Loop (Charles Loop, 1987) subdivision surface algorithm to smooth modern three.js BufferGeometry. — Live Demo —

Stephens Nunnally 26 Dec 3, 2022
Tag-input - A versetile tag input component built with Vue 3 Composition API

TagInput A versetile tag input component built with Vue 3 Composition API. Please read this article to learn how to build this package step by step an

Mayank 12 Oct 12, 2022
Vue-input-validator - 🛡️ Highly extensible & customizable input validator for Vue 2

??️ Vue-input-validator demo! What is this package all about? By using this package, you can create input validators only with the help of a single di

null 14 May 26, 2022
A Bootstrap plugin to create input spinner elements for number input

bootstrap-input-spinner A Bootstrap / jQuery plugin to create input spinner elements for number input. Demo page with examples Examples with floating-

Stefan Haack 220 Nov 7, 2022
A phone input component that uses intl-tel-input for Laravel Filament

Filament Phone Input This package provides a phone input component for Laravel Filament. It uses International Telephone Input to provide a dropdown o

Yusuf Kaya 24 Nov 29, 2022
Tool to sign data with a Cardano-Secret-Key // verify data with a Cardano-Public-Key // generate CIP-8 & CIP-36 data

Tool to sign data with a Cardano-Secret-Key // verify data with a Cardano-Public-Key // generate CIP-8 & CIP-36 data

Martin Lang 11 Dec 21, 2022