Hotkey Plugin
Recently I needed to add hotkeys to our application for quick navigation. The result of this work is the Hotkey plugin, which I’m releasing today.
The Hotkey plugin consists of a Javascript file and three helpers that use it. You can add a hotkey using Javascript directly using the Hotkey.add() function in your application.js, or you can use the helpers in your templates. Here’s a few examples of helper usage:
Calling an action remotely:
<%= hotkey_to_remote :d, :url => {:controller=>'some_controller'} %>
Changing browser location:
<%= hotkey_to :h, :controller => 'home' %>
Calling an arbitrary function:
<%= hotkey_to_function :p, "showPreferencesPanel();" %>
Here we’ve defined three hotkeys; d, h, and p. Pressing a modifier key (which modifier key depends on the browser/platform you’re using) and the letter activates the associated function.
The plugin is very easy to use, and suits our needs. Hopefully it will help out a few others.
Take a look at the README after installation for additional setup information.
Update 2008 I avoid “obtrusive” javascript whenever possible, so I don’t recommend this approach any longer.






