P3D v4 Pausing, slewing & sim rate detection

Hey everyone! My first post here because I'm at a loss with a problem. I'm very much a beginner when it comes to programming and I've used the Simconnect SDK's example as a starting point to make an ACARS-like software in C#. Everything went well with requesting variables, but events seem to be a problem. I tried changing "Managed Client Event" code to trigger with pausing & slewing events. However, out of the listed events regarding these, I found that for example PAUSE_ON and PAUSE_OFF never triggered. PAUSE_TOGGLE only triggered when the actual "P" button was pressed, but not when the add-on's pause at top of descent function triggered it. SIM_RATE_INCR and its pair for decrease never triggered for me when using the menu either.
An example of registering to such an event:
C#:
simconnect.MapClientEventToSimEvent(EVENTS.PAUSE_ON, "PAUSE_ON");
simconnect.AddClientEventToNotificationGroup(NOTIFICATION_GROUPS.GROUP0, EVENTS.PAUSE_ON, false);
etc.
What I'd like is the ability to detect if the sim is paused or not and disallow slewing / sim rate increase while the program is running. I tried to dabble with subscribing to the SLEW_SET system event and set the system event state to SIMCONNECT_STATE.ON or OFF but nothing happened in either case.
I found a few posts on google, some even from this forum, but nothing I tried worked so far. I'd really, really appreciate if someone could help me with this :)
 
You need to be paying attention to SIM STATE... not key input events. Read up on SimConnect_SubscribeToSystemEvent.
 
Thank you very much for the reply, I managed to get the pausing event to work correctly using this page: http://www.prepar3d.com/SDKv3/LearningCenter/utilities/simconnect/simconnect.html#SimConnect_SubscribeToSystemEvent. I found "Frame" as well which is supposed to give information about the sim rate and have subscribed to it like every other system event:
C#:
simconnect.SubscribeToSystemEvent(EVENTS.FRAME, "FRAME");
but it never triggers (neither does PauseFrame), am I missing something here?
 
The FRAME event triggers for every visual frame rendered. It does NOT tell you the sim rate.
 
Hmmm, that's good to know, since the documentation says "Frame: Request notifications every visual frame. Information is returned in a SIMCONNECT_RECV_EVENT_FRAME structure."
and the returned structure is
C#:
struct SIMCONNECT_RECV_EVENT_FRAME : public SIMCONNECT_RECV_EVENT {
  float  fFrameRate;
  float  fSimSpeed;
};
where "fSimSpeed: The simulation rate. For example if the simulation is running at four times normal speed -- 4X -- then 4.0 will be returned."
 
Ah... thus one must read ALL of the SDK... that's not in the description of the actual API call. LOL :oops:

I will test this in C++.
 
The FRAME event DOES tell you both the frame rate and the sim speed. Here is a C++ implementation, if you can make any use of it:

Code:
        case SIMCONNECT_RECV_ID_EVENT_FRAME:
        {
            SIMCONNECT_RECV_EVENT_FRAME *evt = (SIMCONNECT_RECV_EVENT_FRAME*)pData;
            switch(evt->uEventID)
            {
                case EVENT_RECUR_FRAME:
                    SystemVars->fFrameRate = evt->fFrameRate;
                    SystemVars->fFrameDuration = 1.0f/evt->fFrameRate;
                    SystemVars->fSimSpeed = evt->fSimSpeed;

                    break;

                default:
                   break;
            }
            break;
        }
As for FRAME not being triggered, "Frame" system event doesn't fall under the same event ID group as Pause. Pause belongs to SIMCONNECT_RECV_ID_EVENT, and Frame belongs to SIMCONNECT_RECV_ID_EVENT_FRAME (as in the above code snippet).

Make sure you have a case statement for SIMCONNECT_RECV_ID_EVENT_FRAME, where you listen for "Frame" event.
 
Thank you very much, this is exactly what I was missing! Took me all of five minutes to get it to work now, really really appreciate it :)
 
Top