-
-
Notifications
You must be signed in to change notification settings - Fork 108
Playing sounds by sending keystrokes to AutoHotKey
MobiFlight does not support playing sound effects directly, but it is possible to use another very useful piece of open source software to do this.
AutoHotKey lets you define "hotkeys" like Shift-F12 to perform tasks, like, among other things, to play sounds. The software has a lot of features to automate your computer, and many of them are potentially useful in a home cockpit / simulator setup, so please consult the Autohotkey documentation if you want to learn more. But for now, lets continue and define our "play sound" script.
After you have installed AutoHotKey, it does not have a "user interface" per se, but you can create a text file with a .ahk extension with a text editor (please be aware Notepad is very insistent on saving every file with a .txt extension, so you want to View > Show > File name extensions on Windows Explorer to see that your file is whatever.ahk, and not whatever.ahk.txt, so it will be correctly associated with AutoHotKey.
Right click and select "Open" with AutoHotKey (you can see the icon here in the menu to confirm it is associated correctly)
Here's a quick script to play a sound when a given (Shift-F12) keyboard input is detected:
#Requires AutoHotkey v2.0
~+F12::SoundPlay, C:\vPilot\Sounds\SelCal.wav
return
The specifics of this can be found in documentation, but save this to a file like mobiflight-sounds.ahk
and open it by double clicking it or selecting Open from the menu. Now test Shift-F12 and the sound should play. You naturally need to substitute the full path to the wav to something that exists in your computer. If the sound plays, we can create the keyboard send event in MobiFlight like this:
As our synthetic keyboard input is not intended to MSFS2020, but rather to AutoHotKey, we don't need to worry about the limitation of MSFS to not see programmatically generated keyboard input, and the event should work.
In this example we do a low fuel warning sound when the fuel quantity goes below a certain value. This requires an extra step, because MobiFlight supports keyboard shortcuts only from input devices. However we can use a workaround as detailed below:
- We create an output config to read the fuel quantity on selected tank from the simulator
- We then create a Transform rule to set our config value to 1 when the fuel quantity is below a certain value
- Finally we set the "Display" to "Input Action" to create the keyboard event for Autohotkey.
First the fuel quanity read, create a new input configuration:
Set the Transform to if($<3,1,0)
so that our output value is set to 1 whenever the fuel quantity is below 3 gallons, as an example.
To send the keystroke, we will use a bit of a workaround, since MobiFlight only supports keyboard events from input devices like switches. So we set our "Display" to "Input Action" and specify the keyboard shortcut there. Since our value is either 0 or 1, we will choose the "OnPress / OnRelease" option which generates the OnPress event when the fuel quantity gets low enough for a warning.
You can name your Output configuration so that it includes the defined shortcut key, so you can have them nicely listed for when you want to add them to the Autohotkey script.
Happy flying!
- MobiFlight Connector Installation
- Mobiflight Connector BETA version installation
- Modules
- MobiFlight Connector Files Structure
- MobiFlight Connector Uninstall
- Modules Reset to factory default
- Verifying the WASM module installation and locating the MSFS2020 community folder
- Verifying the WASM module installation and locating the MSFS2024 community folder
- Using a Winwing FCU with MobiFlight
- Using VKB controllers with MobiFlight
- Providing logs from MobiFlight
- MobiFlight Connector How does it work
- Mobiflight Connector Main Window
- Flash module with MobiFlight firmware
- Input and Output devices
- Joysticks
- Midi Boards
- Sim Variables (for Output)
- Input Actions
- Merging configuration files
- Disabling specific COM ports
- Examples Output LEDs
- Examples Input Switch
- Example 7 segment display
- Example Servo motor
- Controlling LEDs with an output shift register
- Adding lots of buttons with an input shift register
- Beginner's guide to input multiplexers
- Key Matrix with standard MobiFlight and Multiplexers
- Tutorial Easy Driver and x.27 or x.40 Stepper Motor
- Tutorial for Airbus VS display via 7-Segment LED Module
- Example Analog Input Potentiometer
- Baron G58 Tutorial Gear, Flaps, Mags, ELT Input Output Programming
- Using Mobiflight to control arduino-based 3rd party panels (RealSimGear GNS530)
- How to use a VNH2SP30 DC motor shield with MobiFlight
- Using 3D printer mainboards
- Playing sounds by sending keystrokes to AutoHotKey
- Using the selector knob on a Honeycomb Bravo
- Using an adjustable 12 position switch as a GA starter
- Brightness of LCD displays with I2C
- Using three-position switches
- Transponder with one Rotary
- Workflow for Creating Flight Simulation Panels ‐ Part 1
- MSFS2020 RPN Tips and Tricks
- MSFS2020 Using the Custom Input Code Box
- MSFS2020 Install WASM module and Event List
- MSFS2020 How to Create and Use User Defined Lvars
- MSFS2020 How to Create a Blinking LED configuration
- MSFS2020 User Defined WASM Module Events Best Practices
- MSFS2020 Developer Mode, Model Behavior dialog and Console window
- MSFS2020 PMDG 737‐700 List of Events that require use of FSUIPC7
- MSFS2020 PMDG 737‐700 Calibrate throttle idle and reverse thrust using interpolation (Valkyrie)
- MSFS2020 PMDG 737-700 Chrono unit functions implemented in Mobiflight
- Configuring PMDG 737 Parking Brake Lever Auto-Release with a Servo in Mobiflight
- Using encoder to drive a value back and forth within a given range
- Adding a custom board to MobiFlight
- User guide - Community Board and Custom Devices
- Developing your own custom devices/boards