LivePipe has been deprecated and is no longer maintained.
The author now works primarily on Thorax

HotKey

Programmable keyboard shortcuts.

HotKey provides functionality similar to the accesskey attribute, but has many enhancements that allow for more granular control when creating keyboard driven interfaces.

Active HotKeys on This Page

LetterOptions
control + a{}
control + shift + b{shiftKey: true}
control + shift + alt/option + c{altKey: true, shiftKey: true}
d - no modifiers{ctrlKey: false}
control + e (if second textarea below has focus){element: $('containment_textarea')}
control + down (if second textarea below has focus){element: $('containment_textarea')}

Consoleclear

Remote Triggers

You can call the trigger() method on any HotKey instance to execute the callback. The callback will not receive an Event object in this case, as it would if it had been triggered by the keyboard.

HotKey Element Binding

It is possible to apply the HotKey to a given element by passing the element option. If you bind all HotKeys to elements it is possible to register multiple keys with the same modifiers to different element.

Example


new HotKey('a',function(event){
	log('control + "a" pressed');
});

new HotKey('b',function(event){
	log('control + shift + "b" pressed');
},{
	shiftKey: true
});

new HotKey('c',function(event){
	log('control + shift + alt/option + "c" pressed');
},{
	shiftKey: true,
	altKey: true
});

new HotKey('d',function(event){
	log('"d" pressed');
},{
	ctrlKey: false
});

new HotKey('e',function(event){
	log('control + "e" pressed inside of textarea');
},{
	element: $('containment_textarea')
});

//you can also register against any of the special keys
//defined in prototype.js
//up, down, left, right, esc, return, tab, etc
new HotKey('down',function(event){
	log('control + "down" pressed inside of textarea');
},{
	element: $('containment_textarea')
});

//remote trigger
$('remote_trigger').observe('click',function(event){
	var value = $('remote_trigger_selector').value;
	HotKey.hotkeys.find(function(hotkey){
		//hotkey.letter will always be upper case
		return hotkey.letter == value;
	}).trigger();
	event.stop();
});

Class

ReturnNameDescription
arrayhotkeys

Instance

ReturnNameDescription
HotKeyinitialize(string letter, function callback [,Hash options])
nulldestroy()Also calls disable()
nulldisable()
nullenable()
nulltrigger()Triggers callback, callback will not be passed an Event object.
ElementelementDefaults to document.body
stringletterAlways in upper case.

Options

TypeNameDefaultDescription
boolaltKeyfalse
boolbubbleEventtrueAllow key events to bubble?
boolctrlKeytrueDefaults to true, emulating accesskey behavior.
Element || falseelementfalseAttaches the hotkey to a given element instead of document.body
boolfireOncefalseKeep repeating event while key is pressed?
boolshiftKeyfalse

Events

NameDescription
afterCallback()
beforeCallback()Throwing $break will prevent the callback from being called.