Sign in to follow this  
Rocky

Interesting discover for C//C++ gauge developers

Recommended Posts

With the help of Arne Bartels, Etienne Martin, _ak, and other people, I found the way to use the key event handler that appeared in FS9 SDK, shown in the topic #19735:http://forums.avsim.net/dcboard.php?az=sho..._id=19735&page=It allows you to be informed of any key press through the code. To use it, first define an event handler, a C function that will be called each time a FS key is pressed:static int FSAPI CatchKeyEvent(ID32 event, UINT32 evdata, PVOIDuserdata){...your code here...return 0;}and then, in an initialization function, register this key handler:register_key_event_handler((GAUGE_KEY_EVENT_HANDLER)CatchKeyEvent, NULL);This works perfect, and I discovered even something better: using this function, you can catch all the kinds of events, not only key press. This is especially interesting to read the stick and throttle positions. The stick position can be read through XML variables, but there is no way to read the throttle lever position. I have been searching for years, and I have just found, so I wanted to share this with you:- Create an event handler as shown above- In the code of the handler, if the "event" is KEY_THROTTLE_SET, then "evdata" is the value of the throttle position, from -16383 to 16384- It is the same for the stick X position that controls the aileron. If event is KEY_AILERON_SET, the value is the stick position.- Same for the stick Y position with KEY_ELEVATOR_SET.You can now read all the inputs without needing DirectInput or FSUIPC. I hope it will be useful for some of you...Eric

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Eric,Brilliant piece of work! The events don't even have to be active in FS - you can use this procedure to trap KEY_TOGGLE_AFTERBURNER3 or KEY_TOGGLE_AFTERBURNER4 on a twin jet.I'm sure folks will dream up lots of uses for GAUGE_KEY_EVENT_HANDLER.Thanks for sharing!Doug Dawson

Share this post


Link to post
Share on other sites

Any corresponding code for XML or is this purely a C code issue?Steve

Share this post


Link to post
Share on other sites

Genial - thanks Eric, good work!Just to add one thing: Call unregister_key_event() to remove the handler from the chain when the gauge goes out of scope (window disconnect or the like).I'm wondering if you can return -1 (TRUE) in the handler to tell the handler chain the event was handled, to prevent it from being handled by another handler (this is how the SetWindowsHookEx() handlers tend to work).As far as XML goes, not sure, but callbacks are still only the domain of C/C++ as far as I know.

Share this post


Link to post
Share on other sites

Hi Matt,Nice finally meeting you at the Airshow! I got checked out in the Diamond DA20 today.First, flew with the C172 yoke, the Citabria right handed stick, and now the Diamond left handed stick. I think I am going to go crazy.W. Sieffert

Share this post


Link to post
Share on other sites

>First, flew with the C172 yoke, the Citabria right handed>stick, and now the Diamond left handed stick. I think I am>going to go crazy.:-lol I've got an appointment on Saturday to get checked out in the Arrow. Looking forward to getting some more complex time! :DHow does the Diamond fly? I think that will be the next airplane I'll get checked out in. Visibility must really be something.

Share this post


Link to post
Share on other sites

It flys okay! It feels a little weird to use the left-handed stick, especially since flying the Citabria with the right-handed stick.It flies somewhat like a glider. My flight instructor indicated the aircraft started as a glider. If you come in hot, it will float a long way.If you do fly the Diamond DA20, get the flight instructor to show you the POH sections. It is a real mess! It has been worked over for JAA, CAA, and FAA certification. Trying to find the correct sections for FAA is a pain.W. Sieffert

Share this post


Link to post
Share on other sites

I agree with you, MKaprocki, the post you talk about already explained how to use the event handler (sometimes repetition is not useless though...), but the goal of my post was to emphasize on the fact that this function also allows to read the stick and throttle inputs, which is VERY useful in my opinion.Eric

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