goog.ui.KeyboardShortcutHandler
Classgoog.ui.KeyboardShortcutHandler
> goog.events.EventTarget
> goog.Disposable
goog.ui.KeyboardShortcutHandler(keyTarget)
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.
keyTarget
{goog.events.EventTarget
|EventTarget
}
goog.ui.KeyboardShortcutHandler.EventType
EnumEvents. … more
.MAX_KEY_SEQUENCE_DELAY
{number
}Maximum allowed delay, in milliseconds, allowed between the first and second key in a key sequence.
goog.ui.KeyboardShortcutHandler.Modifiers
EnumBit values for modifier keys. … more
.addEventListener(type, handler, opt_capture, opt_handlerScope)
Inherited from goog.events.EventTarget
.
Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched. Supported for legacy but use goog.events.listen(src, type, handler) instead.
type
{string
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.addOnDisposeCallback(callback, opt_scope)
Inherited from goog.Disposable
.
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
callback
{!Function
}
opt_scope
{Object
=}
.clearKeyListener()
[protected]Removes the listener that was added by link {@link #initializeKeyListener}.
.creationStack
{string
}Inherited from goog.Disposable
.
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
.dispatchEvent(e)
Inherited from goog.events.EventTarget
.
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
e
{string
|Object
|goog.events.Event
}
boolean
}
.dispose()
Inherited from goog.Disposable
.
Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
void
}
.disposeInternal()
[protected]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()
Returns whether all shortcuts (including modifier shortcuts) are treated as if the keys had been passed to the setGlobalKeys function.
boolean
}
.getAlwaysPreventDefault()
Returns whether the default action will always be prevented when a shortcut event is fired. The default value is true.
boolean
}
.getAlwaysStopPropagation()
Returns whether the event will always be stopped from propagating beyond its target when a shortcut event is fired. The default value is false.
boolean
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.getEventType(identifier)
Returns event type for a specific shortcut.
identifier
{string
}
string
}
.getGlobalKeys()
Array
.<number
>}
.getKeyCode(name)
Static method for getting the key code for a given key.
name
{string
}
number
}
.getModifierShortcutsAreGlobal()
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).
boolean
}
.getParentEventTarget()
Inherited from goog.events.EventTarget
.
Returns the parent of this event target to use for bubbling.
goog.events.EventTarget
}
.initializeKeyListener(keyTarget)
[protected]Adds a key event listener that triggers {@link #handleKeyDown_} when keys are pressed.
keyTarget
{goog.events.EventTarget
|EventTarget
}
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.isShortcutRegistered(var_args)
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.
var_args
{...(number
|string
|Array
.<number
>)}
boolean
}
.parseStringShortcut(s)
Builds stroke array from string representation of shortcut.
s
{string
}
Array
.<Object
>}
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.registerShortcut(identifier, var_args)
Registers a keyboard shortcut.
identifier
{string
}
var_args
{...(number
|string
|Array
.<number
>)}
.removeEventListener(type, handler, opt_capture, opt_handlerScope)
Inherited from goog.events.EventTarget
.
Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
type
{string
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.setAllShortcutsAreGlobal(allShortcutsGlobal)
Sets whether to treat all shortcuts (including modifier shortcuts) as if the keys had been passed to the setGlobalKeys function.
allShortcutsGlobal
{boolean
}
.setAlwaysPreventDefault(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.
alwaysPreventDefault
{boolean
}
.setAlwaysStopPropagation(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.
alwaysStopPropagation
{boolean
}
.setGlobalKeys(keys)
Sets the global keys; keys that are safe to always regarded as shortcuts, even if entered in a textarea or input field.
keys
{Array
.<number
>}
.setModifierShortcutsAreGlobal(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).
modifierShortcutsGlobal
{boolean
}
.setParentEventTarget(parent)
Inherited from goog.events.EventTarget
.
Sets the parent of this event target to use for bubbling.
parent
{goog.events.EventTarget
?}
.unregisterAll()
Unregisters all keyboard shortcuts.
.unregisterShortcut(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.
var_args
{...(number
|string
|Array
.<number
>)}