Remoto - VFS
|
This library creates convenient methods for adding keyboard shortcuts to an application. More...
#include "remoto!stdlib:js/include/keyboard.js"
Public Member Functions | |
keyboard (obj, _defaultHandler) | |
destroy () | |
destroy this keyboard listener instance More... | |
init () | |
Return a new instance of a keyboard handler. More... | |
keyHandler (e) | |
listen (jq, _defaultHandler) | |
preventDefault (e) | |
registerCommand (c, f, l, r, p) | |
Register a command with a keyboard listener. More... | |
unregisterCommand (c, r) | |
Unregister a command from a keyboard listener. More... | |
This library creates convenient methods for adding keyboard shortcuts to an application.
To use keyboard commands, listen to a DOM element and attach commands to callbacks:
Alternatively, you can add global commands:
The default instance of keyboard works in the global scope and is created by the paneManager. Be careful when adding global commands. They will be received when no other handler has accepted them and may apply to non-existent objects.
DOCME: describe command syntax, comma separation of strokes ("alt-s,shift-alt-f4"), and also meta keys like shift,command,alt,esc,delete
DOCME: For commands to work, you will need to have an element with focus.
DOCME: there are also options for keydown and keyup
DOCME: when an element has focus and does recognize a keyboard event, it should return true to prevent the command from propagating to other potential callbacks. For instance, ctrl-c should catch at the first opportunity and not propagate to any other potential listeners
DOCME: keyboard event priority
DOCME: keyboard.listen
keyboard | ( | obj, | |
_defaultHandler | |||
) |
obj | |
_defaultHandler |
DOCME
destroy | ( | ) |
destroy this keyboard listener instance
Release memory associated with this keyboard handler instance, which means removing all callbacks by clearing the _command
array.
init | ( | ) |
Return a new instance of a keyboard handler.
This method is called when the keyboard library is requested by require.js. You should never have to call this method manually.
Some default commands are included by default in this initializer:
keyHandler | ( | e | ) |
e |
DOCME
listen | ( | jq, | |
_defaultHandler | |||
) |
jq | |
_defaultHandler |
DOCME
preventDefault | ( | e | ) |
e |
DOCME
registerCommand | ( | c, | |
f, | |||
l, | |||
r, | |||
p | |||
) |
Register a command with a keyboard listener.
c | The command, as a stroke string ("ctrl-a","space","alt-meta-esc") |
f | The callback, which will probably want to be bound() |
l | boolean always |
r | boolean release only |
p | priority (1=first) |
This is really a factory for keyboardCommand objects.
Normally a command is ignored if it happens in an input field inside the listener object. The always
flag will cause it to not be ignored. For instance, if a textarea is inside of your listener, you probably want to be able to type in there, rather than a space
key stroke to trigger something.
unregisterCommand | ( | c, | |
r | |||
) |
Unregister a command from a keyboard listener.
c | The command, as a stroke string ("ctrl-a","space","alt-meta-esc"), which was previously registered |
r | boolean release only |
Searches for registered commands that have a matching keystroke. If release only is true, it will only remove a release-only command.
Returns true if all commands were unregistered.