How to Send Commands
This guide shows you how to send commands to control the simulator from your application. Commands let you toggle autopilot, control lights, deploy gear, and more.
Prerequisites
- A working GameGlue connection (see Build Your First Dashboard if you're starting out)
- The
writescope enabled for your game (e.g.,msfs:writeorxplane:write) - Commands are rejected unless the
writescope is present
Enable Write Access
When initializing the SDK, include the write scope:
javascript
const ggClient = new GameGlue({
clientId: 'your-client-id',
redirect_uri: 'http://localhost:3000',
scopes: ['msfs:read', 'msfs:write'] // Add the write scope
});If you've already authenticated with only read scope, you'll need to log out and log in again to grant the additional permission.
Send a Command
Use sendCommand on your listener:
javascript
const result = await listener.sendCommand('autopilot_on', true);
if (result.status === 'success') {
console.log('Command sent');
} else {
console.error('Failed:', result.reason);
}The first argument is the command name, and the second is the value (usually true for toggle-style commands, or a number for set commands).
Common Commands
These commands work across all supported simulators. Write your code once and it works with MSFS, X-Plane, and future simulators.
Autopilot
javascript
await listener.sendCommand('autopilot_on', true);
await listener.sendCommand('autopilot_off', true);
await listener.sendCommand('autopilot_toggle', true);
await listener.sendCommand('autopilot_heading_hold_on', true);
await listener.sendCommand('autopilot_altitude_hold_on', true);
await listener.sendCommand('autopilot_vs_hold_on', true);
await listener.sendCommand('autopilot_nav_on', true);
await listener.sendCommand('autopilot_approach_on', true);Autopilot Targets
javascript
await listener.sendCommand('set_autopilot_altitude', 35000); // feet
await listener.sendCommand('set_autopilot_heading', 270); // degrees
await listener.sendCommand('set_autopilot_vs', 1800); // fpm
await listener.sendCommand('set_autopilot_speed', 250); // knotsGear and Flaps
javascript
await listener.sendCommand('gear_up', true);
await listener.sendCommand('gear_down', true);
await listener.sendCommand('gear_toggle', true);
await listener.sendCommand('flaps_up', true);
await listener.sendCommand('flaps_down', true);
await listener.sendCommand('set_flaps', 0.5); // 0-1 ratioLights
javascript
await listener.sendCommand('landing_lights_on', true);
await listener.sendCommand('landing_lights_off', true);
await listener.sendCommand('taxi_lights_toggle', true);
await listener.sendCommand('nav_lights_toggle', true);
await listener.sendCommand('beacon_lights_toggle', true);
await listener.sendCommand('strobe_lights_toggle', true);Other Controls
javascript
await listener.sendCommand('spoilers_arm', true);
await listener.sendCommand('spoilers_deploy', true);
await listener.sendCommand('spoilers_retract', true);
await listener.sendCommand('parking_brake_toggle', true);Handle Command Results
Always check the result to handle failures gracefully:
javascript
async function toggleAutopilot() {
const result = await listener.sendCommand('autopilot_on', true);
if (result.status === 'success') {
showNotification('Autopilot enabled');
} else {
showError(`Could not enable autopilot: ${result.reason}`);
}
}Example: Autopilot Control Panel
Here's a complete example of a button that toggles autopilot:
html
<button id="ap-toggle">Toggle Autopilot</button>
<script>
document.getElementById('ap-toggle').addEventListener('click', async () => {
// Check current state from telemetry
const isOn = currentData.autopilot_master;
// Send the opposite command
const command = isOn ? 'autopilot_off' : 'autopilot_on';
const result = await listener.sendCommand(command, true);
if (result.status !== 'success') {
alert('Command failed: ' + result.reason);
}
});
</script>Full Command Reference
See the complete list of available commands for each simulator:
Troubleshooting
"Unauthorized" or permission error?
- Make sure you included the appropriate write scope (e.g.,
msfs:writeorxplane:write) when initializing - Log out and log in again to refresh permissions
Command sends but nothing happens in-game?
- Some commands only work in certain states (e.g., gear won't retract on the ground)
- Check that the simulator is running the simulation (not paused in menus)
"Command not found" error?
- Command names are lowercase with underscores (e.g.,
autopilot_on, notAUTOPILOT_ON) - Check the command reference for your simulator