The following details extensions made to the Lua implementation for the specific purpose of interacting with Virtual Flight Sim Hardware and the flight simulator. You can use them in Lua script files to perform useful functions.

Note that the extensions (functions) are case sensitive as is all Lua scripting code.

Available in All Versions

getbvar

USAGE: getbvar( string variableName )

PURPOSE: Gets the value of a Bespoke variable.

EXAMPLE: x = getbvar("Bespoke Var 10")

EXAMPLE EXPLAINED: This will get the value of Bespoke Var 10 and assign it to the local Lua variable "x".

INFO: The variableName can also be written without spaces e.g. "BespokeVar10".

setbvar

USAGE: setbvar( string variableName, int value )

PURPOSE: Sets the value of a Bespoke variable.

EXAMPLE: setbvar("Bespoke Var 3", 78.5)

EXAMPLE EXPLAINED: This will set the value of Bespoke Var 3 to 78.5.

INFO: The variableName can also be written without spaces e.g. "BespokeVar3".

sendkey

USAGE: sendkey( string character, <enum keyFlag> )

PURPOSE: Sends a key press or combination of key presses to the flight simulator.

EXAMPLE: sendkey ( "L", CONTROL | SHIFT )

EXAMPLE EXPLAINED: This will send the key combination of Control, Shift and "L" to the flight simulator which will toggle the aircraft labels.

INFO:

  • The character parameter can be any key from 0 through to 9 and A through to Z.
  • The parameter keyFlag is optional, so sendkey( "p" ) is valid syntax.
  • Use an empty string if just a keyFlag is to be sent e.g. sendkey( "", TAB)
  • The keyFlag parameter can be combined with multiple keys by using the bitwise OR operator ( | ). e.g. sendkey ( "", SHIFT | TAB | SPACE )
  • The keyFlag parameter can be any combination of the following:

    • BACK
    • TAB
    • ENTER
    • SHIFT
    • CONTROL
    • ALT
    • PAUSE
    • CAPSLOCK
    • ESC
    • SPACE
    • PGUP
    • PGDN
    • END
    • HOME
    • UP
    • DOWN
    • LEFT
    • RIGHT
    • APPS
    • PRTSCRN
    • INSERT
    • DEL
    • NUMLOCK
    • OEM102 (Either the angle bracket key or the backslash key on the RT 102-key keyboard)
    • NUM0
    • NUM1
    • NUM2
    • NUM3
    • NUM4
    • NUM5
    • NUM6
    • NUM7
    • NUM8
    • NUM9
    • NUMMUL
    • NUMADD
    • NUMSUB
    • NUMDEC
    • NUMDIV
    • F1
    • F2
    • F3
    • F4
    • F5
    • F6
    • F7
    • F8
    • F9
    • F10
    • F11
    • F12
    • SCROLL
    • PLUS
    • MINUS
    • PERIOD
    • COMMA
    • OEM1 (For the US standard keyboard, the ';:' key)
    • OEM2 (For the US standard keyboard, the '/?' key)
    • OEM3 (For the US standard keyboard, the '`~' key)
    • OEM4 (For the US standard keyboard, the '[{' key)
    • OEM5 (For the US standard keyboard, the '\|' key)
    • OEM6 (For the US standard keyboard, the ']}' key)
    • OEM7 (For the US standard keyboard, the 'single-quote/double-quote' key)
    • OEM8 (Used for miscellaneous characters; it can vary by keyboard)

sendkeyalt

Use this function exactly as sendkey is used. It provides an alternative way of sending the key presses to the flight simulator if sendkey does not work.

sleep

USAGE: sleep( uint time )

PURPOSE: Suspends processing of the Lua script for the time specified in milliseconds. 1000 milliseconds = 1 Second.

EXAMPLE: sleep(75)

EXAMPLE EXPLAINED: This will suspend the Lua script for 75 milliseconds.

INFO:

  • Use the function to allow time for GIT and the flight simulator to sync and for Events to be completed before reading associated variables indicating switch states.
  • Depending upon your PC's performance, normally a value of 50 or 75 is sufficient.

Available in FSX/FSX SE/Prepar3D/MS FS 2020 Only

sendevt

USAGE: sendevt( string eventName, int eventData )

PURPOSE: Sends an Event and any associated data to the flight simulator.

EXAMPLE: sendevt("KEY_ANTI_ICE_SET_ENG1", 1)

EXAMPLE EXPLAINED: This will send the SimConnect Event KEY_ANTI_ICE_SET_ENG1 to the flight simulator with a data value of 1. The event sets the anti ice function of engine 1. This particular Event requires a data value (most do not and can be set to 0). The data value of 1 means "turn it on" and a value of 0 means "turn if off".

INFO:

  • The eventName can be any type of available Event.
  • Only SimConnect events will accept negative eventData which is usually used for axis values.
  • For PMDG aircraft and for Mouse Click Events, the eventData indicates the mouse action to be used against the event (i.e. what you would do in the Virtual Cockpit). and should be one of the following:
    • MOUSE_RIGHTSINGLE
    • MOUSE_LEFTSINGLE
    • MOUSE_MIDDLESINGLE
    • MOUSE_RIGHTDOUBLE
    • MOUSE_LEFTDOUBLE
    • MOUSE_MIDDLEDOUBLE
    • MOUSE_RIGHTDRAG
    • MOUSE_LEFTDRAG
    • MOUSE_MIDDLEDRAG
    • MOUSE_MOVE
    • MOUSE_DOWN_REPEAT
    • MOUSE_RIGHTRELEASE
    • MOUSE_MIDDLERELEASE
    • MOUSE_LEFTRELEASE
    • MOUSE_WHEEL_FLIP
    • MOUSE_WHEEL_SKIP
    • MOUSE_WHEEL_UP
    • MOUSE_WHEEL_DOWN
    • MOUSE_MOVE_REPEAT
    • MOUSE_LEAVE

    • E.g. sendevt("EVT_OH_ICE_ENGINE_ANTIICE_2", MOUSE_LEFTSINGLE)

sendhevt (MS FS2020 Only)

USAGE: sendhevt( string eventName )

PURPOSE: Sends a HTML Event to the flight simulator.

EXAMPLE: sendhevt("H:A320_Neo_CDU_1_BTN_1)

EXAMPLE EXPLAINED: This will send the HTML Event A320_Neo_CDU_1_BTN_1 to the flight simulator. The event simulates the pressing of button 1 on the CDU of the A320. Note the H: in front of the Event name, indicating its a HTML Event.

INFO:

  • The eventName can be any known HTML Event.

getsvar

USAGE: getsvar( string variableName, enum unitType )

PURPOSE: Gets the value of a SimConnect variable in the format of the chosen unit.

EXAMPLE1: eng2Press = getsvar("GENERAL ENG FUEL PRESSURE:2", "Psi")

EXAMPLE2: eng2Press = getsvar("GENERAL_ENG_FUEL_PRESSURE2", "Psi")

EXAMPLE EXPLAINED: This will get the engine pressure of engine number 2 in Pounds Per Square Inch (Psi) and assign it to the local Lua variable "eng2Press".

INFO:

  • The variableName must be a SimConnect variable. A full list of SimConnect variables along with explanations and unitType's can be found here.
  • Use sendevt or setsvar to change the value of SimConnect variables where applicable.

setsvar

USAGE: setsvar( string variableName, float64 value )

PURPOSE: Sets the value of a SimConnect Variable.

EXAMPLE1: setsvar("GENERAL ENG THROTTLE LEVER POSITION:1", 50)

EXAMPLE2: setsvar("GENERAL_ENG_THROTTLE_LEVER_POSITION1", 50)

EXAMPLE EXPLAINED: This will set the first engine throttle control lever to 50% or, in other words at the half way position.

  • The variableName must be a SimConnect variable.
  • Not all SimConnect variables can be set.
  • Use getsvar to get the value of a SimConnect variable.

getlvar

USAGE: getlvar( string variableName )

PURPOSE: Gets the value of a Local variable (LVar).

EXAMPLE: cdiState = getlvar("CDI Source Selected")

EXAMPLE EXPLAINED: This will get the Local variable value of CDI Source Selected and assign it to the local Lua variable cdiState.

INFO: Do not confuse Lvar local variables with a Lua local variables. Lvar's are variables within a specific aircraft in the flight simulator, where as Lua local variables exist within Lua and get destroyed when the Lua script ends.

setlvar

USAGE: setlvar( string variableName, float64 value )

PURPOSE: Sets the value of a Local Variable (LVar).

EXAMPLE: setlvar("CDI Source Selected", cdiState)

EXAMPLE EXPLAINED: This will set the Local Variable CDI Source Selected to the value contained in the local Lua variable "cdiState".

INFO: Do not confuse Lvar local variables with a Lua local variables. Lvar's are variables within a specific aircraft in the flight simulator, where as Lua local variables exist within Lua and get destroyed when the Lua script ends.

getkvar (Not available in MS FS 2020)

USAGE: getkvar( string variableName )

PURPOSE: Gets the value of an SDK Variable.

EXAMPLE: aiEng1 = getkvar("DATA_FWDOH_ICE_SWITCH_ENG_ANTI_ICE_LEFT")

EXAMPLE EXPLAINED: This will get the PMDG NGX SDK variable value of DATA_FWDOH_ICE_SWITCH_ENG_ANTI_ICE_LEFT and assign it the local Lua variable aiEng1.

INFO:

  • This function can only be used with the PMDG NGX, 777, 747 and the iFly 737 and 747.
  • Use sendevt to change the value of SDK variables where applicable. E.g. sendevt("EVT_OH_ICE_ENGINE_ANTIICE_1", MOUSE_LEFTSINGLE)

Available in X-Plane Only

sendcmd

USAGE: sendcmd( string cmdName )

PURPOSE: Sends a Command to X-Plane.

EXAMPLE: sendcmd("sim/engines/fire_ext_1_on")

EXAMPLE EXPLAINED: This will send the Command "sim/engines/fire_ext_1_on" to X-Plane. The Command turns on the first fire extinguisher.

INFO: n/a

getdref

USAGE: getdref( string datarefName )

PURPOSE: Gets the value of a Dataref.

EXAMPLE: fireExt1On = getdref("sim/cockpit2/engine/actuators/fire_extinguisher_on[1]")

EXAMPLE EXPLAINED: The local Lua variable fireExt1On will be set to a value of 1 if the first fire extinguisher is on, otherwise it will be set 0.

INFO: n/a

setdref

USAGE: setdref( string datarefName, double Value )

PURPOSE: Sets the value of a Dataref.

EXAMPLE: setdref("sim/cockpit/autopilot/heading_mag", 157)

EXAMPLE EXPLAINED:  This sets the autopilots heading to 157 degrees magnetic.

INFO: n/a

 

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.