Home

# Class goog.ui.KeyboardShortcutHandler

Component for handling keyboard shortcuts. A shortcut is registered and bound to a specific identifier. Once the shortcut is triggered an event is fired with the identifier for the shortcut. This allows keyboard shortcuts to be customized without modifying the code that listens for them. Supports keyboard shortcuts triggered by a single key, a stroke stroke (key plus at least one modifier) and a sequence of keys or strokes.

extends goog.events.EventTarget

Instance Method Summary
| `checkShortcut_(?Array.<(Object|null)> strokes) ⇒ boolean` Checks if a particular keyboard shortcut is registered.
| `clearKeyListener()` Removes the listener that was added by link {@link #initializeKeyListener}.

`disposeInternal()`

Unattach listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners, it should be something like this:

    MyClass.prototype.disposeInternal = function() {
    MyClass.superClass_.disposeInternal.call(this);
    // Dispose logic for MyClass
    };

| `getAllShortcutsAreGlobal() ⇒ boolean` Returns whether all shortcuts (including modifier shortcuts) are treated as if the keys had been passed to the setGlobalKeys function.
| `getAlwaysPreventDefault() ⇒ boolean` Returns whether the default action will always be prevented when a shortcut event is fired. The default value is true.
| `getAlwaysStopPropagation() ⇒ boolean` Returns whether the event will always be stopped from propagating beyond its target when a shortcut event is fired. The default value is false.
| `getEventType(string identifier) ⇒ string` Returns event type for a specific shortcut.
| `getGlobalKeys() ⇒ ?Array.<number>`
| `getModifierShortcutsAreGlobal() ⇒ boolean` Returns whether shortcuts with modifiers are treated as if the keys had been passed to the setGlobalKeys function. Ignored if you have called setAllShortcutsAreGlobal(true). Applies only to form elements (not content-editable).
| `getShortcut_(?Array.<number> strokes, number= opt_index, ?Object= opt_list) ⇒ (Object|null|string)` Returns shortcut for a specific set of strokes.
| `handleKeyDown_(?goog.events.BrowserEvent event)` Keypress handler.
| `handleMacGeckoKeyUp_(?goog.events.BrowserEvent e)` Handler for when a keyup event is fired in Mac FF2 (Gecko 1.8).
| `handleWindowsKeyPress_(?goog.events.BrowserEvent e)` Handler for when a keypress event is fired on Windows.
| `handleWindowsKeyUp_(?goog.events.BrowserEvent e)` Handler for when a keyup event is fired on Windows.
| `initializeKeyListener((EventTarget|goog.events.EventTarget|null) keyTarget)` Adds a key event listener that triggers {@link #handleKeyDown_} when keys are pressed.
| `interpretStrokes_(number initialIndex, ?Object args) ⇒ ?Array.<(Object|null)>` Parses the variable arguments for registerShortcut and unregisterShortcut.

`isPossiblePrintableKey_(?goog.events.BrowserEvent e) ⇒ boolean`

Returns whether this event is possibly used for typing a printable character. Windows uses ctrl+alt (a.k.a. alt-graph) keys for typing characters on European keyboards. Since only Firefox provides a method that can identify whether ctrl+alt keys are used for typing characters, we need to check whether Windows sends a keypress event to prevent firing shortcut event if this event is used for typing characters.

`isShortcutRegistered((Array.<number>|null|number|string|undefined) var_args) ⇒ boolean`

Verifies if a particular keyboard shortcut is registered already. It has the same interface as the unregistering of shortcuts. param {number} keyCode Numeric code for key param {number=} opt_modifiers Bitmap indicating required modifier keys. goog.ui.KeyboardShortcutHandler.Modifiers.SHIFT, CONTROL, ALT, or META. The two parameters can be repeated any number of times to create a shortcut using a sequence of strokes. A string representation of the shortcut can be supplied instead see {@link #registerShortcut} for syntax. In that case the method only takes one argument.

| `isValidShortcut_(?goog.events.BrowserEvent event) ⇒ boolean` Checks if a given keypress event may be treated as a shortcut.
| `registerShortcut(string identifier, (Array.<number>|null|number|string|undefined) var_args)` Registers a keyboard shortcut.
| `setAllShortcutsAreGlobal(boolean allShortcutsGlobal)` Sets whether to treat all shortcuts (including modifier shortcuts) as if the keys had been passed to the setGlobalKeys function.
| `setAlwaysPreventDefault(boolean alwaysPreventDefault)` Sets whether to always prevent the default action when a shortcut event is fired. If false, the default action is prevented only if preventDefault is called on either of the corresponding SHORTCUT_TRIGGERED or SHORTCUT_PREFIX events. If true, the default action is prevented whenever a shortcut event is fired. The default value is true.
| `setAlwaysStopPropagation(boolean alwaysStopPropagation)` Sets whether to always stop propagation for the event when fired. If false, the propagation is stopped only if stopPropagation is called on either of the corresponding SHORT_CUT_TRIGGERED or SHORTCUT_PREFIX events. If true, the event is prevented from propagating beyond its target whenever it is fired. The default value is false.
| `setGlobalKeys(?Array.<number> keys)` Sets the global keys; keys that are safe to always regarded as shortcuts, even if entered in a textarea or input field.
| `setModifierShortcutsAreGlobal(boolean modifierShortcutsGlobal)` Sets whether to treat shortcuts with modifiers as if the keys had been passed to the setGlobalKeys function. Ignored if you have called setAllShortcutsAreGlobal(true). Applies only to form elements (not content-editable).
| `unregisterAll()` Unregisters all keyboard shortcuts.

`unregisterShortcut((Array.<number>|null|number|string|undefined) var_args)`

Unregisters a keyboard shortcut by keyCode and modifiers or string representation of sequence. param {number} keyCode Numeric code for key param {number=} opt_modifiers Bitmap indicating required modifier keys. goog.ui.KeyboardShortcutHandler.Modifiers.SHIFT, CONTROL, ALT, or META. The two parameters can be repeated any number of times to create a shortcut using a sequence of strokes. A string representation of the shortcut can be supplied instead see {@link #registerShortcut} for syntax. In that case the method only takes one argument.

Static Method Summary
| `getKeyCode(string name) ⇒ number` Static method for getting the key code for a given key.
| `makeKey_(number keyCode, number modifiers) ⇒ number` Constructs key from key code and modifiers. The lower 8 bits are used for the key code, the following 3 for modifiers and the remaining bits are unused.
| `parseStringShortcut(string s) ⇒ ?Array.<(Object|null)>` Builds stroke array from string representation of shortcut.
| `setShortcut_(?Object parent, ?Array.<(Object|null)> strokes, ?string identifier)` Adds or removes a stroke node to/from the given parent node.