• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

With simconnect detect when I'm not in flight

Messages
13
Country
belgium
Hi,
actually I've made my interface that get informations from the game all time like (acceleration, speed , plane name ...).
Even in the menu the data are updated.
I initialize my listener like this
my_simconnect.OnRecvOpen += new SimConnect.RecvOpenEventHandler(simconnect_OnRecvOpen);
my_simconnect.OnRecvQuit += new SimConnect.RecvQuitEventHandler(simconnect_OnRecvQuit);
my_simconnect.OnRecvException += new SimConnect.RecvExceptionEventHandler(simconnect_OnRecvException);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Title", null, SIMCONNECT_DATATYPE.STRING256, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ACCELERATION WORLD X", "Feet per second squared", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ACCELERATION WORLD Y", "Feet per second squared", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "ACCELERATION WORLD Z", "Feet per second squared", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
...

Which parameters I can use to detect when I'm not flying. When I'm in the menu ?

Thanks for your help.
 
You can try one of this simvars:

USER INPUT ENABLED
SIM DISABLED
IS USER SIM

I'm just guessing, but I estimate that some will work, and then you tell us which one was the winner!
tip: check values with simvar watcher first.
 
Hi thanks for the answer but
USER INPUT ENABLED : Is input allowed from the user . For me it will always be true

Where do you find IS USER SIM ?
 
I try
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "GROUND ALTITUDE", "Meters", SIMCONNECT_DATATYPE.INT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
I got something like 4,1995579896506E-322
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "SIM ON GROUND", "bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
always 0
my_simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "SIM DISABLED", "bool", SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
always 0
 
There are actually a number of states where the user is "not flying," depending on your definition of that (eg. "active pause" vs. the "esc menu," or not even having a flight loaded maybe).

In any case, I think your best best may be to subscribe to sim system events. Some work better, or at least more "as expected" than others, so you will need to experiment. I haven't tested this extensively in a couple versions.


HTH,
-Max
 
Max always brings good ideas, I hadn't thought about the events...


SimRequests the state of the simulation. If 1 is returned, the user is in control of the aircraft, if 0 is returned, the user is navigating the UI. This is the same state that notifications can be subscribed to with the "SimStart" and "SimStop" string with the SimConnect_SubscribeToSystemEvent function.

SimStopThe simulator is not running. Typically the user is loading a flight, navigating the shell or in a dialog.
 
Hi,
Good idea .
I don't understand how to subscribe to the event listener.
I've made something like this
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Stop, "SimStop");
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Start, "SimStart");
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Pause_EX1, "Pause_EX1");
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Pause, "Pause");
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Paused, "Paused");
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Unpaused, "Unpaused");
and declare an enum
public enum EVENT_CTRL
{
Sim_Pause,
Sim_Paused,
Sim_Crashed,
Sim_Start,
Sim_Stop,
Sim_Unpaused,
Sim_Pause_EX1,
}
and now, what is the function to get the events ?

Thanks
 
I modify like this
// listen to events
my_simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);

my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Stop, "SimStop");
my_simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENT_CTRL.Sim_Stop, false);
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Start, "SimStart");
my_simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENT_CTRL.Sim_Start, false);
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Pause_EX1, "Pause_EX1");
my_simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENT_CTRL.Sim_Pause_EX1, false);
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Pause, "Pause");
my_simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENT_CTRL.Sim_Pause, false);
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Paused, "Paused");
my_simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENT_CTRL.Sim_Paused, false);
my_simconnect.MapClientEventToSimEvent(EVENT_CTRL.Sim_Unpaused, "Unpaused");
my_simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENT_CTRL.Sim_Unpaused, false);
and I add the function
void simconnect_OnRecvEvent(SimConnect sender, SIMCONNECT_RECV_EVENT recEvent)
{
switch (recEvent.uEventID)
{
case (uint)EVENT_CTRL.Sim_Crashed:
Console.WriteLine("crashed");
break;
case (uint)EVENT_CTRL.Sim_Unpaused:
Console.WriteLine("Sim_Unpaused");
break;
case (uint)EVENT_CTRL.Sim_Pause:
Console.WriteLine("Sim_Pause");
break;
case (uint)EVENT_CTRL.Sim_Paused:
Console.WriteLine("Sim_Paused");
break;
case (uint)EVENT_CTRL.Sim_Pause_EX1:
Console.WriteLine("Sim_Pause_EX1");
break;
case (uint)EVENT_CTRL.Sim_Start:
Console.WriteLine("Sim_Start");
break;
case (uint)EVENT_CTRL.Sim_Stop:
Console.WriteLine("Sim_Stop");
break;

}

}

but the event never fire

Any idea ?
 
You do not need to map any Client events. These are Sim events. To subscribe to one of them all you need is:

C#:
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Stop, "SimStop");

And then the event(s) will be delivered to your simconnect_OnRecvEvent() handler as you expect.

The exception is, IIRC, when a file name is passed as part of the event data, then the C# event handler name is OnRecvEventFilename().

HTH,
-Max
 
Here is the solution thanks to max

// listen to events
my_simconnect.OnRecvEvent += new SimConnect.RecvEventEventHandler(simconnect_OnRecvEvent);


my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Stop, "SimStop");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Start, "SimStart");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Pause_EX1, "Pause_EX1");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Pause, "Pause");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Paused, "Paused");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Unpaused, "Unpaused");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim, "Sim");


void simconnect_OnRecvEvent(SimConnect sender, SIMCONNECT_RECV_EVENT recEvent)
{
switch (recEvent.uEventID)
{
case (uint)EVENT_CTRL.Sim_Crashed:
Console.WriteLine("crashed");
break;
case (uint)EVENT_CTRL.Sim_Unpaused:
Console.WriteLine("Sim_Unpaused");
break;
case (uint)EVENT_CTRL.Sim_Pause:
Console.WriteLine("Sim_Pause");
break;
case (uint)EVENT_CTRL.Sim_Paused:
Console.WriteLine("Sim_Paused");
break;
case (uint)EVENT_CTRL.Sim_Pause_EX1:
Console.WriteLine("Sim_Pause_EX1");
break;
case (uint)EVENT_CTRL.Sim_Start:
Console.WriteLine("Sim_Start");
break;
case (uint)EVENT_CTRL.Sim_Stop:
Console.WriteLine("Sim_Stop");
break;

}

}

public enum EVENT_CTRL
{
Sim_Pause,
Sim_Paused,
Sim_Crashed,
Sim_Start,
Sim_Stop,
Sim_Unpaused,
Sim_Pause_EX1,
Sim,
}

The strange thing thing is the running mode.

When I launch a free flight I print
Sim_Stop
Sim_Start
Sim_Unpaused
Sim_Pause_EX1
Sim_Pause
Sim_Paused
Sim_Pause_EX1
Sim_Pause

when I click on the ready to fly button

Sim_Unpaused
Sim_Pause_EX1
Sim_Pause

When I push the Esc button to stop the fly

Sim_Paused
Sim_Pause_EX1
Sim_Pause

So the Sim_pause is useless Only use the events

Sim_Unpaused
Sim_Paused
Sim_Stop
Sim_Start

Thanks for your help guys

Hope it will help someone else
 
Last edited:
Hi max
the problem is th same with one or multiple event . none fired on simconnect_OnRecvEvent()

Perhaps you could post more complete code of what you're trying. I can assure you it does work, in general. Do you have the message dispatch running (the bit that calls SimConnect.ReceiveMessage())?

-Max
 
Glad to hear you got it working! What was the problem before you edited your last post?

When I push the Esc button to stop the fly

Sim_Paused
Sim_Pause_EX1
Sim_Pause

Just curious, what event(s), if any, do you get when you go into/out of "active pause" mode?
There were some issues with detecting active pause in the past, and I was hoping the new Sim_Pause_EX1 (with its extra parameter) would solve the problem finally. Haven't had a chance to test it.

Thanks,
-Max
 
Hi,
Back again when you are in the main menu the event are the same as when you are in flight.
When you come from selecting you party to a fly the events are called like this:
Sim_Stop
Sim_Paused
Sim_Start
Sim_Stop
Sim_Start
Sim_Unpaused
Sim_Paused
Sim_Unpaused
and when you make a pause
Sim_Paused

When you go to the main menu the events are called like this :
Sim_Paused
Sim_Stop
Sim_Start
Sim_Stop
Sim_Start
Sim_Unpaused

It is the same thing , do you have an idea another data to test ?
 
Do you try this event "SimStop"?
not the "Sim" one...


SimStopThe simulator is not running. Typically the user is loading a flight, navigating the shell or in a dialog.
 
Yes of course
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Start, "SimStart");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Stop, "SimStop");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Paused, "Paused");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Unpaused, "Unpaused");
my_simconnect.SubscribeToSystemEvent(EVENT_CTRL.Sim_Crashed, "Crashed");

it works until you don't go back to the main menu as I said before
 
IIRC the sim loads "MainMenu.FLT" flight file when opening the main menu. This would be a 'FlightLoaded' sim event (again IIRC).
 
For what you say, you have tried: "SimConnect_SubscribeToSystemEvent" (Pause, Pause_EX1, etc etc)

There is an other option: "SimConnect_RequestSystemState" (options with potential: DialogMode), just guessing...
 
Back
Top