Adds some methods for creating shortcuts to the Keyboard Class.
Associates a event handler with a name and description.
Syntax
myKeyboard.addShortcut('save', {
'keys': 'ctrl+s',
'description': 'Save the current document',
'handler': doSaveFunc
});
Arguments
- name - (string) The name of the shortcut.
- shortcut - (object)
- keys - (string (optional)) Same as the argument that you would pass to addEvent. If not passed it will not automatically add it as an event on the Keyboard.
- description - (string) A brief description of the functionality.
- handler - (function) The event handler function.
- keys - (string (optional)) Same as the argument that you would pass to addEvent. If not passed it will not automatically add it as an event on the Keyboard.
Returns
- (object) A new instance of Keyboard
Same as addShortcut but can send many as key, value pairs.
Syntax
myKeyboard.addShortcut({
'save', {
'keys': 'ctrl+s',
'description': 'Save the current document',
'handler': doSaveFunc
},
'open', {
'keys': 'ctrl+o',
'description': 'Open a document',
'handler': doOpenFunc
}
});
Arguments
- obj - (object) An object of key value pairs to be sent to addShortcut.
Returns
- (object) A new instance of Keyboard
Gets all shortcuts on the Keyboard instance.
Syntax
myKeyboard.getShortcuts();
Returns
- (array) An array of shortcuts on the Keyboard.
Get a shortcut with the name passed in.
Syntax
myKeyboard.getShortcut('save');
Arguments
- name - (string) The name of the shortcut to lookup.
Returns
- (object or null) The shortcut with the name if found.
Unbinds the shortcuts passed in and rebinds them to the keys that are passed in.
Syntax
myKeyboard.rebind('shift+s', shortcutObjs);
Arguments
- keys - (string) The new shortcut for the shortcuts.
- shortcuts - (object or array[object]) One or more shortcuts to rebind.
Gets all active shortcuts using the passed in Keyboard or Keyboard.manager as a starting point.
Syntax
myKeyboard.getActiveShortcuts();
Arguments
- keyboard - (object: optional) The Keyboard object used to start looking. Keyboard.manager by default.
Returns
- (array) An array containing all of the active shortcuts.
Goes through all active keyboards using the passed in keyboard or Keyboard.manager as a starting point and attempts to find a shortcut with the name passed in.
Syntax
Keyboard.getShortcut('save');
Arguments
- name - (string) The name of the shortcut to lookup.
- keyboard - (object (optional)) The keyboard to start looking on.
Returns
- (object or null) The shortcut with the name if found.
Same as Keyboard.getShortcut but gets all that match the name.
Syntax
myKeyboard.getShortcuts('save');
Arguments
- name - (string) The name of the shortcut to lookup.
- keyboard - (object (optional)) The keyboard to start looking on.
Returns
- (array) An array of shortcuts with the name passed in.