Jump to content
The simFlight Network Forums

Help with capturing keyboard commands


Recommended Posts

Hi Pete,

I've been working for the past few weeks on setting up a system to capture keyboard commands to send them to my panel.

I had created a system using SimConnect that works like this:

               if ( CheckInput(KB_INPUT_FD2))
		{
			hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_KEY_FD2);
			hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, INPUT_GROUP, EVENT_KEY_FD2);
			hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_KEY_FD2, KB_INPUT_FD2, EVENT_KEY_FD2);
			hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_KEY_FD2, SIMCONNECT_STATE_ON);
			hr = SimConnect_SetInputGroupPriority(hSimConnect, INPUT_KEY_FD2, SIMCONNECT_GROUP_PRIORITY_HIGHEST);
		}

So first I check if there is a valid key combination set for the command (in this case pushing FD2 button) and then I do the (un)usual SimConnect mumbo jumbo to make sure SimConnect fires an event when the keys are pressed.

               case EVENT_KEY_FD2:
			// Do stuff
		break;

First I noticed that if I added 5 keyboard commands, the last one in the list wouldn't work, when I added a sixth, the fifth would work again but the sixth wouldn't. So I added a dummy key command capture at the end. After adding some more commands, however even this approach wouldn't work anymore. I ended up with > 40 keyboard commands and the last 25 or so simply never get cought. And yes my "hr"'s always return S_OK.

now there is off course the "old" system of capturing the keyboard in FSX using DirectInput so I started from scratch and tried to get that to work but there I have 2 issues:

- DirectX always treats the keyboard as if in Querty format!

- I noticed that (at least on my setup) DirectInput "hangs" and never forgets previous keyboard inputs. So press "A" and then "H" and after you release the button DirectInput will still return that A and H are pressed! I found one forum entry on the internet of someone complaining he has the same issue, but this was never resolved. The only way to fix this (at least as far as I found) is by stopping dinput each time a key is pressed and restarting the connection

So what to do now ? Is the SimConnect keyboard system not meant to be used with more than a few keyboard commands and therefore inherently flawed or is there a trick that I missed ?

Is DirectInput the way forward but what to do then with the hanging keys and even more importantly with the Qwerty format issue ?

Hope you can help me out !

Björn

Link to comment
Share on other sites

So what to do now ? Is the SimConnect keyboard system not meant to be used with more than a few keyboard commands and therefore inherently flawed or is there a trick that I missed ?

Is DirectInput the way forward but what to do then with the hanging keys and even more importantly with the Qwerty format issue ?

Sorry, I have no experience at all with either SimConnect key captures nor DirectInput. I've always simply processed the WM_KEYDOWN and WM_KEYUP messages being sent to the main FS window, which I subclass.

Regards

Pete

Link to comment
Share on other sites

Hi Pete,

Ah yes, haven't tried that yet ! Will give that a go also... can you also capture multiple keypresses that way (e.g. shift-Ctrl-Tab-A) ?

Can you give some hints on how to set up this subclassing ? I understand it involves using CallWindowProc but I have no idea how to set this up...

Björn

Link to comment
Share on other sites

Ah yes, haven't tried that yet ! Will give that a go also... can you also capture multiple keypresses that way (e.g. shift-Ctrl-Tab-A) ?

Yes, you just need to watch the KEYDOWNs and KEYUPs and set flags accordingly. ALT is a little awkward as it can cause the KEYDOWN to be aa SYSKEYDOWN (or something like that). If you deal with ALT you need a little extra code.

Can you give some hints on how to set up this subclassing ? I understand it involves using CallWindowProc but I have no idea how to set this up...

The Microsoft developer help on all that is pretty good. I'd need to look it up. I don't remember it all I'm afraid.

Incidentally, if you are using FSUIPC in any case you could, instead, use FSUIPC's hot Keys facilities and let it do the trapping for you.

Regards

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.