MOUSE AIRCRAFT
The MouseAircraft aircraft is a preset of the WASMAircraft modular aircraft, illustrates how to obtain mouse information from a WebAssembly gauge. Additionally, it showcases how to trigger sound events using local variables from WebAssembly. Once the WASM Aircraft package has been built, this module will be available for flying from the aircraft selection screen:

The WasmModules.sln file (found in the Sources folder of the project) will allow you to compile the source-code with Microsoft Visual Studio (2019 or 2022) in order to create the MouseModule.wasm WebAssembly module which will then be loaded by the game. Once compiled, the module will automatically be copied into the following folder:
[ROOT]\PackageSources\SimObjects\Airplanes\MyCompany_Wasm_Aircraft\presets\mycompany\MouseAircraft\panel
Note that if you make changes to the C++ code and recompile the mouse WASM module, you will have to build your package again. This can be done while the plane is used within the simulation.
Testing
Once you have built the aircraft and selected it, you can go into a Free Flight and you will see three panels in the cockpit:

Each of these gauge displays is explained below, along with the source file that they use:
MouseInformation.cpp: This display provides debug information of mouse displacement and button actions. The display will light up the mouse buttons used -Lfor the left button,Mfor the middle button,Wfor the wheel, andRfor the right button - as well as display the position of the cursor and an updating list of the different mouse events sent.
Toggle.cpp: This display is used to show how to detect mouse events inside of a rectangular area on the gauge screen. Clicking one of the red, green, or blue, rectangles will change the colour of the grey rectangle.
TriggerSound.cpp: This display simply contains a button that - when pressed - will play a sound. It provides an example on how to control both single and continuous sound events

It is worth noting that the sound event is first declared insounds\sound.xml, linking theWwiseEventwith theLocalVaras described in the WwiseSampleProject. Then, theLocalVaris controlled from the WebAssembly module:int sound_lvar_id = lvarregister_named_variable("LocalVar_in_sound.xml"); ... set_named_variable_value(sound_lvar_id, trigger_value);
Mouse Events Additional Information
As described in the Handling Mouse Events section, mouse events can be obtained from a Gauge by declaring the corresponding mouse callback, eg:
MSFS_CALLBACK void GAUGENAME_mouse_callback(float fX, float fY, unsigned int iFlags)
{
switch (iFlags)
{
case MOUSE_MOVE:
...
break;
case MOUSE_LEFTSINGLE:
...
break;
case MOUSE_LEFTDOUBLE:
...
break;
case MOUSE_LEFTDRAG:
...
break;
case MOUSE_LEFTRELEASE:
...
break;
case MOUSE_RIGHTSINGLE:
...
break;
case MOUSE_RIGHTDOUBLE:
...
break;
case MOUSE_RIGHTDRAG:
...
break;
case MOUSE_RIGHTRELEASE:
...
break;
case MOUSE_MIDDLESINGLE:
...
break;
case MOUSE_MIDDLEDOUBLE:
...
break;
case MOUSE_MIDDLEDRAG:
...
break;
case MOUSE_MIDDLERELEASE:
...
break;
case MOUSE_WHEEL_DOWN:
...
break;
case MOUSE_WHEEL_UP:
...
break;
}
}
Related Topics