ssCore.Keyboard.setNotify

Tell SWF Studio about an event that you want to receive notifications for.


Availability:

First available in version 3.0 build 2039.


Input Parameters:

event - The event you want to receive notifications for. Valid values include: onKey and onHotKey.

keyName - [Optional] - Used with the OnHotKey event to identify the hotkey being registered, you will need this name to remove the hotkey later.

key - [Optional] - The virtual key code for hotkey. Used with the OnHotKey event.

shift - [Optional] - When set to 1, the Shift key must be pressed with the key to trigger the hotkey. Used with the OnHotKey event. Valid values include: 0 and 1.

ctrl - [Optional] - When set to 1, the Ctrl key must be pressed with the key to trigger hotkey. Used with the OnHotKey event. Valid values include: 0 and 1.

alt - [Optional] - When set to 1, the Alt key must be pressed with the key to trigger hotkey. Used with the OnHotKey event. Valid values include: 0 and 1.

win - [Optional] - When set to 1, the Windows key must be pressed with the key to trigger hotkey. Used with the OnHotKey event. Valid values include: 0 and 1.


Output Parameters:

result - Notification data for the specified event (see description of events for more detail).


Asynchronous Mode:

When this method is called asynchronously, a return object containing the output parameters is passed to the specified callback function.

ssCore.Keyboard.setNotify( paramsObject [, callbackParamsObject] [, errorParamsObject] );


Synchronous Mode:

When this method is called synchronously, a return object containing the output parameters is returned to the caller immediately.

var returnObject = ssCore.Keyboard.setNotify( paramsObject );


Notes:

None.


Events:

name - onKey
type - triggered
result - "blocked,state,keycode,alt,shift,ctrl"

The onKey event is triggered when the application window has focus and the user presses or releases any key. The data passed to the event handler consists of six values. The blocked value is "1" if the key has been blocked by a call to Keyboard.block. The state value contains "o" if the key is up (released) and "1" if the key is down. The keycode is the Windows virtual keycode that represents the key that has been pressed or released. The alt, shift and ctrl values indicate the state of the Atl, Shift and Ctrl keys (respectively) when the onKey event is triggered, where "0" means the key is up and "1" means the key is down.

function OnKey(ret_obj, cb_obj, err_obj)
{
    v = ret_obj.result.split(",")

    s = "no";
    if (v[0] == "1") s = "yes";

    ssDebug.trace("blocked: " + s);

    s = "up";
    if (v[1] == "1") s = "down";

    ssDebug.trace("state: " + s);

    ssDebug.trace("virtual key code: "+ v[2]);

    s = "";
    if (v[3] == "1") s += "alt ";
    if (v[4] == "1") s += "shift ";
    if (v[5] == "1") s += "ctrl ";

    ssDebug.trace("shift keys down: " + s);
}

name - onHotKey
type - triggered
result - keyname

The onHotKey event is triggered when the hotkey defined in the call to Keyboard.setNotify is pressed. Hotkey notifications will be triggered regardless of whether your application has focus or not. The data passed to the event handler, keyname is the name of the hotkey as it appears in the keyName argument of the call to Keyboard.setNotify.

ssCore.Keyboard.setNotify({event:"OnHotKey", keyName:"hotkey1", shift:"0", ctrl:"0", key:"32"}, {callback:onHotKey});
ssCore.Keyboard.setNotify({event:"OnHotKey", keyName:"hotkey2", shift:"1", ctrl:"0", key:"32"}, {callback:onHotKey});
ssCore.Keyboard.setNotify({event:"OnHotKey", keyName:"hotkey3", shift:"0", ctrl:"1", key:"32"}, {callback:onHotKey});

function onHotKey(ret_obj, cb_obj, err_obj)
{
    ssDebug.trace("key: " + ret_obj.result);
}

To remove a hotkey event you have to call Keyboard.clearNotify and pass the name of the hotkey you want to disable. Once this is done you will no longer receive notifications for the specified event, all other registered hotkeys will continue to generate notifications until they are removed.

ssCore.Keyboard.clearNotify({event:"OnHotKey", keyName:"hotkey2"});