• 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.

Problem with maskable events

DragonflightDesign

Resource contributor
Messages
1,369
Country
northernireland
Maskable events doesn't seem to operate the way I expect. Code follows:
Code:
    hr = SimConnect_MapClientEventToSimEvent(hSimConnect, KEY_A);
    hr = SimConnect_MapInputEventToClientEvent(hSimConnect, KEYBOARD_INPUT, "a", KEY_A, true); 
    // Sign up for notifications 
    hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_KEYBOARD, KEY_A);     
    // Set a high priority for the group
//    hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_KEYBOARD, KEY_A, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
    hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_KEYBOARD, SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE);

// At another place in the code where I can be sure the sim is fully started:
        if (isLoaded)
        {
            hr = SimConnect_SetInputGroupState(hSimConnect, KEYBOARD_INPUT, SIMCONNECT_STATE_ON); 
        }
When I press the A key it's correctly trapped by the event but the cockpit camera also activates. It's my expectation that I'll trap the A key but the cockpit camera does not change, so I've either missed or misunderstood something (or both). I've looked at the PMDG-style code here:


and it would be easy enough to copy it and modify it suit my need, but that would rather defeat the object of trying to find out what I've done wrong and knowing how maskable events work.
 
You need a SimConnect_SetInputGroupPriority after the SimConnect_SetInputGroupState perhaps? It's in the PMDG code but not in yours.
 
No, that wasn't it. I modified the throttlecontrol sample from the P3D SDK so that nothing of my code could possibly be getting in the way, but the result was the same.
 
It seems that it might have been sort-of working all along, but not as I expected. This is the modified SDK throttlecontrol code:
Code:
        // Set up a data definition for the throttle control
        hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_THROTTLE, "GENERAL ENG THROTTLE LEVER POSITION:1", "percent");

        // Request a one-sec event which we'll use to connect
        hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_1SEC, "1sec");

        // Create two private key events to control the throttle
        hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_A);
        hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_S);

        // Sign up for notifications
        hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_KEYS, EVENT_A, true);
        hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_KEYS, EVENT_S, true);

        // Link the events to the keyboard
        hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_KEYS, "A", EVENT_A, true);
        hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_KEYS, "S", EVENT_S, true);

        // Set a high priority for the group
        hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_KEYS, SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE);

        // Set the input to the highest priority
        hr = SimConnect_SetInputGroupPriority(hSimConnect, INPUT_KEYS, SIMCONNECT_GROUP_PRIORITY_HIGHEST_MASKABLE);

        // Ensure the input events are on
        hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_KEYS, SIMCONNECT_STATE_ON);
What I expected from that is the A and S keys would be intercepted and increase/decrease the throttle (they do). What also happens - which I did not expect - is that the A key changes the internal views and the S key changes the external views at the same time as changing the throttle setting. I thought that masking the key inputs would prevent the keypresses from going through to prepar3d.exe?

Just in case you're wondering what that EVENT_1SEC is doing:
Code:
                case EVENT_1SEC:
                {
                    // Send this request to get the user aircraft id, then stop coming though here
                    // This allows you to stop racing the sim for a sim start avent
                    if (i == 0)
                    {
                        i = 1;
                        hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_THROTTLE, DEFINITION_THROTTLE, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
                    }
                }
                break;
Saves having to restart P3D every time and race it to getting the console app running in that short period between SimConnect starting up and 'sim_start' being transmitted. Damn silly idea that was on someone's part! (Variable i is a static int).
 
Last edited:
Back
Top