How to Send Commands
This guide shows you how to send commands to control the game 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:write)
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).
Common Commands
Here are frequently used commands:
Autopilot:
javascript
await listener.sendCommand('AUTOPILOT_ON', true);
await listener.sendCommand('AUTOPILOT_OFF', true);
await listener.sendCommand('AP_HDG_HOLD_ON', true);
await listener.sendCommand('AP_ALT_HOLD_ON', true);Lights:
javascript
await listener.sendCommand('LANDING_LIGHTS_ON', true);
await listener.sendCommand('TOGGLE_NAV_LIGHTS', true);
await listener.sendCommand('TOGGLE_STROBES', true);Flight Controls:
javascript
await listener.sendCommand('GEAR_TOGGLE', true);
await listener.sendCommand('FLAPS_DOWN', true);
await listener.sendCommand('PARKING_BRAKES', 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
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:
Troubleshooting
"Unauthorized" or permission error?
- Make sure you included the appropriate write scope (e.g.,
msfs: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 MSFS has focus or is running the simulation (not paused in menus)
"Command not found" error?
- Verify the command name matches exactly (case-sensitive)
- Check the command reference for valid commands