Classes (extension) | GUI | External Control > Keyboard

KeyDownActions : Object
ExtensionExtension

a class supplying editable platform-specific key-mappings

Description

KeyDownActions supplies key-mappings for different platforms as classvars. Furthermore it's responsible for handling global shortcuts. Global shortcuts that work independently from SClang or any GUI. The actions connected to the shortcuts can be invoked independently from which application is currently the frontmost.

Class Methods

KeyDownActions.keyCodes

KeyDownActions.keyCodes = value

An IdentityDictionary, containing key-mappings in key-value pairs: e.g.

$e -> 14,

or

\esc -> 53,

A key can be a single Char or a Symbol, the number is the keycode returned for the key. The snippet creates a window that has a keyDownAction associated which posts key-value pairs for arbitrary keystrokes. You may use this code if the default keyCodes doesn't match the ones on your platform. Edit keyCodes by using the KeyCodesEditor.

(
w = Window("keyDown action");
w.view.keyDownAction_({ |view, char, mod, unicode, keycode, key|
    "\t\t\t% -> \t\t\t\t%,\n".postf(char.asCompileString, keycode);
});
w.front;
)

Returns:

KeyDownActions.arrowsModifiersQt

KeyDownActions.arrowsModifiersQt = value

This special classvar turned out to be necessary as the modifiers when using the arrow-keys are different to the ones using other keys. Use the following snippet to determine (arrow) modifiers on your platform (you may use the same code to test the result of the other modifier related classvars as well).

(
w = Window("keyDown (arrow) modifiers");
w.view.keyDownAction_({ |view, char, mod, unicode, keycode, key|
    "\t\t\t% (%) -> \t\t\t\t%,\n".postf(char.asCompileString, keycode, mod);
});
w.front;
)

Returns:

KeyDownActions.arrowsModifiersCocoa

KeyDownActions.arrowsModifiersCocoa = value

Same as arrowsModifiersQt. Even though this variable exists using Linux too it has no relevance there.

Returns:

KeyDownActions.modifiersQt

KeyDownActions.modifiersQt = value

Normal modifiers using Qt

Returns:

KeyDownActions.modifiersCocoa

KeyDownActions.modifiersCocoa = value

Normal modifiers using Cocoa

Returns:

Setting Shortcuts

KeyDownActions.setShortcuts(view, shortcutsDict)

Set the key-down actions of the given View according to the shortcuts given in shortcutsDict.

NOTE: Though argument view will usually be a View or one of its subclasses it can be any object that responds to a method named keyDownAction. Note also the corresponding instance method KeyDownActionsEditor: -setShortcuts

Arguments:

view

a View or any object that responds to keyDownAction

shortcutsDict

a Dictionary or (better) an IdentityDictionary defining the key-down actions that shall be added to the given view. The dictionary must be formatted as follows:

IdentityDictionary[
    <Symbol containing a key or key combination> -> (
        func: <a Function>,
        keyCode: KeyDownActions.keyCodes[<a Char>],
        modifierQt: KeyDownActions.<modifiersQt or arrowsModifiersQt>[<modifier key>],
        modifierCocoa: KeyDownActions.<modifiersCocoa or arrowsModifiersCocoa>[<modifier key>]
    ),
    /* ... more slots ... */
]

Returns:

this (KeyDownActions)

KeyDownActions.globalShortcuts

KeyDownActions.globalShortcuts = value

Set or get global shortcuts. Global shortcuts will independently from the program that is currently the frontmost one. However, they depend on a Synth that listen's to the user's keystrokes. The listening Synth will use one UGen per key. Also note that global shortcuts can only use a single keystroke (no combination of modifier and key).

Returns:

KeyDownActions.globalShortcutsEnabled

KeyDownActions.globalShortcutsEnabled = bool

Enable or disable global shortcuts.

Arguments:

bool

a Boolean

Returns:

a Boolean (if used as getter)

Inherited class methods

Instance Methods

Inherited instance methods