Jump to content
Sign in to follow this  
Guest GregWoods

Problem getting the button up event to fire in MapInputEventToClientEvent using a joystick

Recommended Posts

Guest GregWoods

Greetings all.I've been playing around with SimConnect, and some of the concepts are slowly sinking in!I have the following managed code which simply displays the message 'LANDING LIGHTS ON' whilst a button is being pressed, then clears it when the button is released. This is being done purely for experimentation - my final application will be a radio stack. Note that I intentionally do not actually fire the FSX Landing lights events. My goal is simply to intercept keyboard or joystick inout, and have my code do some stuff.The problem.When the following code is run using key 'z' in MapInputEventToClientEvent, my code works fine.When I swap this for 'joystick:0:button:0', when I hold down button 0, the LANDING_LIGHTS_ON event fires correctly, but when I let go of the button, LANDING_LIGHTS_ON fires again instead of LANDING_LIGHTS_OFF.Any ideas why?I read another post about supplying all arguments to MapInputEventToClientEvent , but I'm already doing that.Help!Greg Woods

private void simconnect_OnRecvOpen(SimConnect sender, SIMCONNECT_RECV_OPEN data){    textBox_Connect.Text = "Connected to FSX";    button_Connect.Text = "Disconnect";    /********* LANDING LIGHTS *******    Get joystick input from FSX (no need for DirectInput) and call our own function      Even though were not currently doing anything in FSX with our keypress/joystick input,      we must still wire up the MapClientEventToSimEvent, (and AddClientEventToNotificationGroup ??)      but we pass null for thefsx event to fire in MapClientEventToSimEvent.    */    simconnect.MapClientEventToSimEvent(EVENTS.LANDING_LIGHTS_ON, null);    simconnect.AddClientEventToNotificationGroup(NGROUP.LIGHTS_GROUP, EVENTS.LANDING_LIGHTS_ON, false);    simconnect.MapClientEventToSimEvent(EVENTS.LANDING_LIGHTS_OFF, null);    simconnect.AddClientEventToNotificationGroup(NGROUP.LIGHTS_GROUP, EVENTS.LANDING_LIGHTS_OFF, false);    //  Test of keyboard down and up actions: press 'z' to flash landing lights. Works for keyboard    //simconnect.MapInputEventToClientEvent(INPUTGROUP.LIGHTS_GROUP, "z", EVENTS.LANDING_LIGHTS_ON, 0, EVENTS.LANDING_LIGHTS_OFF, 0, false);    //  Test of joystick down and up actions: press sidewinder button 1 (front trigger) to flash landing lights    //  doesn't work for button UP event using joystick    simconnect.MapInputEventToClientEvent(INPUTGROUP.LIGHTS_GROUP, "joystick:0:button:0", EVENTS.LANDING_LIGHTS_ON, 0, EVENTS.LANDING_LIGHTS_OFF, 0, false);    simconnect.SetInputGroupState(INPUTGROUP.LIGHTS_GROUP, (uint)SIMCONNECT_STATE.ON);    //simconnect.SetInputGroupPriority(INPUTGROUP.LIGHTS_GROUP, SimConnect.SIMCONNECT_GROUP_PRIORITY_HIGHEST);}void simconnect_OnRecvEvent(SimConnect sender, SIMCONNECT_RECV_EVENT data){    switch(data.uEventID)    {        case (uint)EVENTS.LANDING_LIGHTS_ON:            txtLandingLights.Text = "LANDING LIGHTS ON";            break;        case (uint)EVENTS.LANDING_LIGHTS_OFF:            txtLandingLights.Text = "";            break;    }}

Share this post


Link to post
Share on other sites
Guest GregWoods

Additional info:I've tried this in unmanaged C++ by modifying the 'Input Event' sample with the following sections of code:

static enum EVENT_ID {    NOEVENT,    EVENT_BRAKES,    DOWN,    UP, };

                case DOWN:                    printf("\nDOWN: %d", evt->dwData);                    break;                case UP:                    printf("\nUP: %d", evt->dwData);                    break;

        hr = SimConnect_MapClientEventToSimEvent(hSimConnect, DOWN, NULL);        hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, DOWN);        hr = SimConnect_MapClientEventToSimEvent(hSimConnect, UP, NULL);        hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, UP);        hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "z", DOWN, 1, UP, 2, false);        hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST);        hr = SimConnect_SetInputGroupState(hSimConnect, INPUT0, SIMCONNECT_STATE_ON);

Output when 'z' key is used for key down and key up:DOWN: 1DOWN: 1DOWN: 1DOWN: 1 DOWN: 1 DOWN: 1UP: 2The down event is repeated. Not exactly what I wanted, but I can work around it. Both events fire, and the correct data is passed through.Output when 'joystick:0:button:0' is used for button down and button up:DOWN: 1DOWN: 0The down event is not repeated whilst I'm holding down the joystick button, which is good.However, the UP event is not fired. As I found in the managed code sample in my first post, the DOWN event is fired a second time, passing 0 as it's data parameter.I can't see any other explanation other than this being a bug.

Share this post


Link to post
Share on other sites
DOWN: 1DOWN: 1DOWN: 1DOWN: 1 DOWN: 1 DOWN: 1UP: 2The down event is repeated. Not exactly what I wanted, but I can work around it. Both events fire, and the correct data is passed through.
The keyboard repetition is part of Windows, or the keyboard driver. The notifications you get are simply the result of the WM_KEYDOWN's being received and the final WM_KEYUP.
Output when 'joystick:0:button:0' is used for button down and button up:DOWN: 1DOWN: 0The down event is not repeated whilst I'm holding down the joystick button, which is good.However, the UP event is not fired. As I found in the managed code sample in my first post, the DOWN event is fired a second time, passing 0 as it's data parameter.
I think it is merely an omission of more explanation in the SimConnect documentation. "Up" events only apply to Keys. With joysticks you get notified of state changes. Think is terms of joystick axes, for example. You get the changing values of the axis. There's no "up" at all. Buttons are simple 2-state devices, POVs 4 or 8 state, axes multiple.RegardsPete

Win10: 22H2 19045.2728
CPU: 9900KS at 5.5GHz
Memory: 32Gb at 3800 MHz.
GPU:  RTX 24Gb Titan
2 x 2160p projectors at 25Hz onto 200 FOV curved screen

Share this post


Link to post
Share on other sites
Guest GregWoods

Thanks for the explanation - though the API using MapInputEventToClientEvent to handle both keyboard and joystick inputs, when they behave so differently, may be called bad design rather than an documentation omission :)I think I've figured out enough to be able to do what I want, which is joystick button chords. Thanks again. I suspect I'll have lots more questions as I get to grips with the API!

Share this post


Link to post
Share on other sites
Thanks for the explanation - though the API using MapInputEventToClientEvent to handle both keyboard and joystick inputs, when they behave so differently, may be called bad design rather than an documentation omission :)
Well, I wouldn't disagree with that. There should have been different API functions for such different input types. I expect the first thing that happens in the SimConnect code is that the paths diverge!At least it works once you know. All the events you need are provided, and that's the main thing.RegardsPete

Win10: 22H2 19045.2728
CPU: 9900KS at 5.5GHz
Memory: 32Gb at 3800 MHz.
GPU:  RTX 24Gb Titan
2 x 2160p projectors at 25Hz onto 200 FOV curved screen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...