My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads

Description

Hotkeys.js is a Prototype plugin for binding custom hotkeys and keyboard shortcuts.

Features

  • Lightweight - 3.8 KB minified
  • Cross-browser - Tested on Internet Explorer 6/7/8, Firefox 2/3, Google Chrome
  • Browser-integrated
    • It can bind and overwrite keyboard shortcuts already registered by the browser (like CTRL+S)
    • When the focus is inside input fields or textareas it doesn't interfere

Usage

  • Download hotkeys.js or hotkeys-min.js
  • Include the script in your page, after the Prototype library:
  • <script type="text/javascript" src="prototype.js"></script>
    <script type="text/javascript" src="hotkeys.js"></script>
  • Bind any combination of keys:
  • Hotkeys.bind(combination, function, [param1, param2, etc]);
  • You can call Hotkeys.bind() how many times you like, there is no limit to the number of hotkeys that can be registered, and binding can even be chained:
  • Hotkeys.bind(combination, function).bind(anotherCombination, anotherFunction)[.bind(...];

Example

Calling a function that adds two numbers when pressing ALT+A together:

function add(a, b) {
    alert(parseInt(a) + parseInt(b));
}
Hotkeys.bind("alt+a", add, 3, 4);

Key aliases

This is the entire list of available keys:

  • backspace
  • tab
  • enter
  • shift
  • ctrl
  • alt
  • pause
  • caps
  • esc
  • pgup, pgdown
  • end
  • home
  • left
  • up
  • right
  • down
  • ins
  • del
  • from 0 to 9
  • from a to z
  • left-win, right-win - Win keys
  • select
  • num0 to num9
  • multiply, add, subtract, dec, divide
  • f1 to f12
  • num - Num lock
  • scroll - Scroll lock
  • semi-colon
  • equal
  • comma
  • dash
  • period
  • slash
  • grave
  • open-bracket
  • backslash
  • close-braket
  • single-quote

Powered by Google Project Hosting