qnx.system.ShortcutGroup

ShortcutGroup

Properties | Methods | Events | Examples


Packageqnx.system
Classpublic class ShortcutGroup
InheritanceShortcutGroup Inheritance flash.events.EventDispatcher

A ShortcutGroup allows you to register custom keyboard shortcuts and be notified when they are triggered. A ShortcutEvent.SHORTCUT_SELECTED event is dispatched when one of the keyboard shortcuts is activated.

Class information:
BlackBerry 10 Version:   10.0.0

View the examples

See also

ShortcutManager



Public Properties

 PropertyDefined By
  keyboardEventDispatcher : IEventDispatcher
Gets or sets an IEventDispatcher that dispaches KeyboardEvents.
ShortcutGroup

Public Methods

 MethodDefined By
  
ShortcutGroup(dispatcher:IEventDispatcher)
Creates a new ShortcutGroup instance.
ShortcutGroup
  
addShortcut(keys:Array):void
Adds a shortcut key combination to the ShortcutGroup.
ShortcutGroup
  
destroy():void
Destroys the ShortcutGroup.
ShortcutGroup
  
Removes all registered shortcuts from the ShortcutGroup.
ShortcutGroup
  
removeShortcut(keys:Array):Boolean
Removes a shortcut key combination from the ShortcutGroup.
ShortcutGroup

Events

 Event Summary Defined By
  Dispatched when the user triggers a keyboard shortcut that has been added to the ShortcutGroup.ShortcutGroup

Property Detail

keyboardEventDispatcher


keyboardEventDispatcher:IEventDispatcher

Gets or sets an IEventDispatcher that dispaches KeyboardEvents.


Implementation

public function get keyboardEventDispatcher():IEventDispatcher
public function set keyboardEventDispatcher(value:IEventDispatcher):void

Constructor Detail

ShortcutGroup()


public function ShortcutGroup(dispatcher:IEventDispatcher)

Creates a new ShortcutGroup instance.

Parameters

dispatcher:IEventDispatcher — An IEventDispatcher to listen to for KeyboardEvents.

Method Detail

addShortcut()


public function addShortcut(keys:Array):void

Adds a shortcut key combination to the ShortcutGroup. Note that the order is important since the user has to press the keys in the order the shortcut defines them. For example, registering [Keyboard.SHIFT, Keyboard.A] means that Shift must be pressed before the A key in order to trigger the shortcut.

Parameters

keys:Array — An Array of keys that must be pressed in order to trigger the shortcut.

destroy()


public function destroy():void

Destroys the ShortcutGroup. All ShortcutGroup instances should be destroyed to properly clean up their internal listeners.

removeAllShortcuts()


public function removeAllShortcuts():void

Removes all registered shortcuts from the ShortcutGroup.

removeShortcut()


public function removeShortcut(keys:Array):Boolean

Removes a shortcut key combination from the ShortcutGroup. For the best performance pass in the same keys array that was passed to ShortcutGroup.addShortcut().

Parameters

keys:Array — An array of keys previously registered with addShortcut.

Returns

Boolean — Returns true if the shortcut was found and removed.

Event Detail

shortcutSelected


Event Object Type: qnx.events.ShortcutEvent
ShortcutEvent.type property = qnx.events.ShortcutEvent.SHORTCUT_SELECTED

Dispatched when the user triggers a keyboard shortcut that has been added to the ShortcutGroup.

Triggered when all the keys in a custom shortcut are pressed in order.

The ShortcutEvent.SHORTCUT_SELECTED constant defines the value of the type property of the event object for an shortcutSelected event.

The properties of the event object have the following values:

PropertyValue
bubblesfalse
cancelablefalse
currentTargetThe object that is actively processing the Event object with an event listener.
keysAn Array of keys that triggered the event.
typeShortcutEvent.SHORTCUT_SELECTED

Examples

The following example creates a new ShortcutGroup and listens for the Shift and C keys to be pressed in that order, as well as the Shift and V keys. When either combination has been pressed the onShortcutSelected method is called and the key combination that was pressed is traced.

package
{
    import qnx.events.ShortcutEvent;
    import qnx.system.ShortcutGroup;
    import qnx.system.ShortcutManager;
    import flash.ui.Keyboard;
    
    [SWF(height="1280", width="768", frameRate="60", backgroundColor="#FFFFFF")]    
    public class KeyboardShortcutExample extends Sprite
    {
        public function KeyboardShortcutExample()
        {
            initializeUI();
        }
        
        private function initializeUI():void
        {
            var group:ShortcutGroup = ShortcutManager.shortcutManager.createShortcutGroup();
             group.addEventListener(ShortcutEvent.SHORTCUT_SELECTED, onShortcutSelected);
            group.addShortcut([Keyboard.SHIFT, Keyboard.C]);
            group.addShortcut([Keyboard.SHIFT, Keyboard.V]);
        }
        
        private function onShortcutSelected(event:ShortcutEvent):void
        {
            trace("selected keyboard shortcut: " + event.keys);
        }
    }
}
     




comments powered by Disqus