GetKeyboardState
 
 
 

GetKeyboardState

Introduced

v1.0

Description

Retrieves the current status of all the virtual keys.

Note: This command uses output arguments. C# and some scripting languages (such as JScript, PerlScript and Python) don't support arguments passed by reference so you need to use the best workaround for your situation:

For scripting languages this command returns an ISIVTCollection which you can use to get the output arguments.

For C# you can use the XSIApplication.ExecuteCommand method to call this command. ExecuteCommand packs the output arguments into a C# System.Object containing an Array of the output arguments (see Calling Commands from C#).

Scripting Syntax

GetKeyboardState( [KeyCode], [Shift] );

Parameters

Parameter Type Description
KeyCode Long Not implemented.
Shift siKeyboardState Returns an integer mask which corresponds to the state of the Shift(1), Ctrl(2), and Alt(4) keys.

Examples

1. VBScript Example

dim l_ModifierKey
GetKeyboardState , l_ModifierKey
if CBool(CByte(1) And CByte(l_ModifierKey)) then
        LogMessage "Shift pressed"
elseif CBool(CByte(2) And CByte(l_ModifierKey)) then
        LogMessage "Ctrl pressed"
elseif CBool(CByte(4) And CByte(l_ModifierKey)) then
        LogMessage "Alt pressed"
else
        LogMessage "No modifier key pressed."
end if

2. JScript Example

/*
        This example illustrates how to call the GetKeyboardState command and access 
        the output argument called Shift; this contains the modifier key state.
*/
var rtn = GetKeyboardState();
var mod;
// get modifier by index
modifier = rtn(1);
LogMessage( "modifier = " + modifier, siInfo );
// get modifier by argument name
modifier = rtn("Shift");
LogMessage( "modifier = " + modifier, siInfo );
var str = "";
if ( 1 & modifier )
{
        str = "Shift "
}
if ( 2 & modifier )
{
        str += "Ctrl "
}
if ( 4 & modifier )
{
        str += "Alt "
}
if ( str != "" ) 
{
        LogMessage( str + "pressed", siInfo );
}
else
{
        LogMessage( "No modifier key pressed.", siInfo );
}
//INFO : "modifier = 7"
//INFO : "modifier = 7"
//INFO : "Shift Ctrl Alt pressed"