Acunote's Javascript Keyboard Shortcuts Framework
Try It
- Mozilla Firefox Extension
- Greasemonkey Script
- (adds keyboard shortcuts to news.yc, reddit and digg learn more)
Source Code
Resources
Overview
Acunote Shortcuts is a JavaScript library providing everything you need to make add rich keyboard shortcut functionality to a web application. With a few lines of code you can have Gmail-like single and multi-key keyboard shortcuts covering the essential functionality.
Acunote Shortcuts was extracted from Acunote, an online project management application for Scrum, XP, Agile and common sense.
Demo
| j | has not been used yet |
| <Shift>+r | has not been used yet |
| g then i | has not been used yet |
| b then a then z | has not been used yet |
Features
- Simple to use: just declare a keymap defining what key sequences to bind to what functions and the library does the rest.
- Supports single key (e.g. "j") and compound key sequence shortcuts (e.g. "g i") of any length.
- Supports binding of any letter, number, symbol, punctuation keys. <Shift> modifier is also supported. (e.g. "?").
- Works in Mozilla Firefox 1+, Internet Explorer 6+, Opera 8+, Safari, Konqueror.
- Lightweight, does not depend on any other JavaScript library.
- Visual feedback in the echo area.
- Optional Ruby on Rails helper provides convenient way to define shortcuts from Ruby. Global and page-specific keymap are supported and are merged at the runtime.
- Greasemonkey userscript with an examples of using adding shortcuts to News.YC, Reddit and Digg. Includes code to add Gmail-style cursor.
- Open Source, MIT license.
Four Simple Steps To Use Shortcuts from Pure Javascript
- Download the archive and unpack it to your web site or application directory.
-
Include shortcuts library and styles somewhere inside <head> tag.
<script src="shortcuts.js" type="text/javascript"></script> <link href="shortcuts.css" type="text/css" media="screen"/>
-
Configure shortcuts as a javascript hash.
<script type="text/javascript"> var SHORTCUTS = { 'h': function() { alert('Help!'); }, 'f': { 'o': { 'o': function() { alert('"foo" has been typed!'); } } }, 'b': { 'a': { 'R': function() { alert('"baR" has been typed!'); }, 'z': function() { alert('"baz" has been typed!'); } } } } </script> -
Initialize keyboard shortcuts listener on page load.
<body onload="shortcutListener.init();">
Four Simple Steps To Use Shortcuts from Ruby on Rails
Rails helper supports global and page-specific keymaps and merges these at runtime.
This way you can define global shortcuts for the whole site in the layout, and modify them as needed for specific pages. This example uses this functionality.
-
Configure global shortcuts in your layout template.
<% @global_shortcuts = { :h => "alert('Help!');", :f => { :o => { :o => "alert('"foo" has been typed!');" } } } %> -
Add local page shortcuts to the page template.
<% @page_shortcuts = { :b => { :a => { :R => "alert('"bar" has been typed!');", :z => "alert('"baz" has been typed!');" } } } %> -
Place acunote_shortcuts_helper.rb into you app/helpers directory and
include it into ApplicationHelper class
module ApplicationHelper include AcunoteShortcutsHelper end -
Call render_shortcuts where your javascript code is rendered
<script type="text/javascript"> <%= render_shortcuts %> </script>
Then h and foo will be available for all the pages and one page will have additional bar and baz shortcuts
News.YC, Reddit, Digg Keyboard Shortcuts For Your Browser
This Firefox Extension and Greasemonkey Script add Gmail-style cursor, navigation and post management shortcuts to YCombinator News, Reddit and Digg. It includes aconote-shortcuts.js library, and site-specific code to setup shortcuts for each of these.
| Cursor Movement | Notes | |
|---|---|---|
| j | move cursor up | |
| k | move cursor down | |
| Post management | ||
| o, <Enter> | open original post | |
| <Shift>+o | open comments | |
| u | back to news list | |
| Voting | ||
| v then u | vote up | "dig" on Digg |
| v then d | vote down | "bury" on Digg |
| Other | ||
| g then i | open "index" page | News.YC |
| g then n | open "newest" page | News.YC, Reddit |
| g then h | open "hot" page | |
| g then b | open "browse" page | |
| g then s | open "saved" page | |
| g then r | open "recommended" page | |
| g then t | open "stats" page | |
| ? | show help | |
Firefox Extension
Ready to use. Just install it.
Greasemonkey Script
To use Greasemonkey script with Firefox 2+ install Greasemonkey extension and load Acunote shortcuts userscript. For Safari 3+ install GreaseKit plugin and load Acunote shortcuts userscript.
To add support for a new site:
- download the script source
- copy and paste the DummySource function, rename and adapt it to your needs
- add @include http://your-site.com* to the list of directives at the beginning of the Greasemonkey script
- add your site to the SupportedSites map at the end of the Greasemonkey script
- post your solution to the mailing list and if it's cool, we'll include it in the next Acunote Shortcuts release
Acunote: Powered by Shortcuts
Acunote, our project management software, is the best way to see Acunote Shortcuts library in action. Just about everything is accessible through keyboard. Acunote also includes more keyboard features, which will be extracted into the library in the future - advanced list selector (like keyboard feed selector in Google Reader or QuickSilver), Esc listeners, accesskey-based shortcuts, etc.
Contributing
Acunote Shortcuts framework and Greasemonkey script are released under MIT license. Your contributions are welcome.
Updates
- 2008-04-08 — first public release
Bring Shortcuts Back To The Web!