Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
msfs-simconnect-api-wrapper
Advanced tools
A convenient SimConnect API for playing with Microsoft Flight Simulator 2020
A JavaScripty wrapper around EvenAR's excellent node-simconnect with a simplified API.
See test.js for the basics, which you can run (with MSFS open and sitting on the apron with a plane =) using npm test
.
This is still a work in progress, although it does wrap all simvars and system events at the moment.
Install with npm install msfs-simconnect-api-wrapper
.
For examples on how to use this, see the examples dir.
This API manager has an argless constructor that does nothing other than allocate internal values. In order to work with MSFS, you need to call the connect
function first, which can take an options object of the following form:
{
retries: positive number or Infinity
retryInterval: positive number, representing number of seconds (not milliseconds) between retries,
onConnect: callback function with the node-simconnect handle as its only argument.
onRetry: callback function retry interval as its only argument, triggers _before_ the next attempt is scheduled.
}
For example, we can set up an API object and have it start trying to connect, eventually dropping us into the code that knows it has an MSFS connection using the following boilerplate:
import { MSFS_API } from "./msfs-api.js";
const api = new MSFS_API();
api.connect({
retries: Infinity,
retryInterval: 5,
onConnect: () => run(),
onRetry: (_, interval) => console.log(`Connection failed: retrying in ${interval} seconds.`),
});
function run() {
console.log(`We have an API connection to MSFS!`);
//
// ...your code here...
//
}
The API has a single property .connected
which is either undefined
or true
and can be used to determine whether the API has a connection to MSFS outside of code that relies on the onConnect
callback.
connect(opts?)
, sets up a connection to MSFS, see above for an explanation of opts
.on(evtDefinition, handler)
, starts listening for a specific simconnect event with a specific handler. Returns a corresponding arg-less off()
function to clean up the listener. See the "System events" section below for details on the event definition.off(evtDefinition, handler)
, stop listening for a specific simconnect event with a specific handler. You'll typically not need to call this, just use the function that on
returns. See the "System events" section below for details on the event definition.get(...propNames)
, accepts a list of simvars (with spaces or underscores) and async-returns a key/value pair object with each simvar as key (with spaces replaced by underscores).schedule(handler, interval, ...propNames)
, sets up a periodic call to handler
every interval
milliseconds with the result of get(...propNames)
. Returns an arg-less off()
to end the scheduled call.set(propName, value)
, accepts a single simvar and the value its should be set to. This will throw for simvars that are not settable.trigger(triggerName, value?)
, triggers a simconnect event, with optional value.All event names in https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/API_Reference/Events_And_Data/SimConnect_SubscribeToSystemEvent.htm are supported as constants on the SystemEvents
object. Event names are keyed using UPPER_SNAKE_CASE. That is, the first few events are encoded as:
const SystemEvents = {
...
AIRCRAFT_LOADED: {
name: `AircraftLoaded`,
desc: `Request a notification when the aircraft flight dynamics file is changed. These files have a .AIR extension. The filename is returned in a SIMCONNECT_RECV_EVENT_FILENAME structure.`,
},
CRASHED: {
name: `Crashed`,
desc: `Request a notification if the user aircraft crashes.`,
},
...
Meaning you if you wanted to listen for the AircraftLoaded
event, you would use api.on(SystemEvents.AIRCRAFT_LOADED, functionHandleHere)
.
All simvars are supported, barring several simvars with data types for which I need to figure out how to actually deference then, such as LatLonAlt structs, or the (super rare) bool/string combination.
"not verified" means that they've been ported, marked settable where appropriate, pass the test run, but they've not been individually confirmed to be correct with respect to the documentation yet.
SimEvents are resolved by key name, so as long as you use a valid keyname, you can trigger it. See https://docs.flightsimulator.com/html/Programming_Tools/Event_IDs/Event_IDs.htm for the full list (there are... a lot).
File an issue if you want to help get this wrapper to 100% simvar and event support! Even if you just want to help verify a few variables, that's a few variables fewer that I'll need to run through =)
FAQs
A convenient SimConnect API for playing with Microsoft Flight Simulator 2020
The npm package msfs-simconnect-api-wrapper receives a total of 27 weekly downloads. As such, msfs-simconnect-api-wrapper popularity was classified as not popular.
We found that msfs-simconnect-api-wrapper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.