Sign in to follow this  
Guest _ak

Key Event Handlers

Recommended Posts

This will notify you whenever a key_event is triggered.void FSAPI EventHandler (ID32 event, UINT32 evdata, PVOID userdata){ if (event == KEY_SPOILERS_TOGGLE) { //user has toggled the spoilers }}In the gauge callback:register_key_event_handler((GAUGE_KEY_EVENT_HANDLER)EventHandler, 0);andunregister_key_event_handler((GAUGE_KEY_EVENT_HANDLER)EventHandler,0);Hope it'll be as useful to you as it's been to us. :-)

Share this post


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

Hey all,Guess no one realizes the potential for this, or they already knew it? Or perhaps the number of C programmers has gone down :-hmmm

Share this post


Link to post
Share on other sites

>Hey all,>>Guess no one realizes the potential for this, or they already>knew it? Or perhaps the number of C programmers has gone down>:-hmmmWell, I found it interesting enough to print out and add to my "appendix" for the SDK... :)

Share this post


Link to post
Share on other sites

Bad thing that you can't filter events like in keyboard hooks

Share this post


Link to post
Share on other sites

Had finally time to try this, yes pretty useful, as I need to remap several events in a new project. It does the same as ... ..in XML. Don't know to fetch the "evdata" equivalent in XML yet (M:..?)Arne BartelsP.S. and never forget the FSAPI in C! The definition in fs9gauges.h should look like this:typedef void FSAPI VGAUGE_KEY_EVENT_HANDLER (ID32 event, UINT32 evdata, PVOID userdata);typedef VGAUGE_KEY_EVENT_HANDLER *GAUGE_KEY_EVENT_HANDLER;

Share this post


Link to post
Share on other sites

This is great!While you can't filter it, you can probably undo it if you know what it was...

Share this post


Link to post
Share on other sites

I am still hoping one of you gurus comes up with a way to intercept a key input in XML so that it can actioned by XML but NOT actioned by the flightsim itself.I really want the starter to be activated by an external button on a joystick, which means(If I am correct) that the button or keyboard event MUST be assigned to the starter. Problem is the darned starter in FS9 always runs regardless of whether the engine has failed, the battery is off etc etc when it is assigned to a key or button, so by "grabbing" the input away from the computer and filtering it through an XML gauge, I can prevent this.Steve

Share this post


Link to post
Share on other sites

>This will notify you whenever a key_event is triggered.>register_key_event_handler((GAUGE_KEY_EVENT_HANDLER)EventHandler,>0);>and>unregister_key_event_handler((GAUGE_KEY_EVENT_HANDLER)EventHandler,>0);I think it is not absolutelly correct. I even gives you an event if the input focus is NOT on FS window. For example if you type something in a multisession chat window (or SB3, IvAp chat) then this event is triggered causing big troubles.I checked a solution where they used this to activate/deactivate the non-standard autopilot. It switched AP status and nearly killed me while I was chatting with the ATC.I checked the same with the default Cessna and there pressing "Z" key in the chat window does NOT affected AP status.I am just looking for the OFFICIAL and correct way to handle keyboard input.Gabor

Share this post


Link to post
Share on other sites

There is none. Gauges are not supposed to read keypresses.However, there are ways to do it, e.g. using key event handlers, but that is NOT reading keypresses directly. With key event handlers you can fetch the key events, which are already interpreated keypresses. You might also use DIrectInput to read the keyboard "parallel" to FS, other ways might be also possible.Arne Bartels

Share this post


Link to post
Share on other sites

Almost all payware FMC have a keyboard input button. If it is pressed every keypress goes to the gauge and not to the flightsim. How can they do that?I managed to read the keys with DirectX, but how can I prevent FS from reading the key too?

Share this post


Link to post
Share on other sites

>P.S. and never forget the FSAPI in C! The definition in>fs9gauges.h should look like this:>typedef void FSAPI VGAUGE_KEY_EVENT_HANDLER (ID32 event,>UINT32 evdata, PVOID userdata);>typedef VGAUGE_KEY_EVENT_HANDLER *GAUGE_KEY_EVENT_HANDLER;Or more precisely:typedef void (*GAUGE_KEY_EVENT_HANDLER) (ID32 event, UINT32 evdata, PVOID userdata);Note that MS fixed the missing "void" from previous versions, although it was assumed by most compilers (at least theirs for sure).Patrick

Share this post


Link to post
Share on other sites

>I am still hoping one of you gurus comes up with a way to>intercept a key input in XML so that it can actioned by XML>but NOT actioned by the flightsim itself.>>I really want the starter to be activated by an external>button on a joystick, which means(If I am correct) that the>button or keyboard event MUST be assigned to the starter.>Problem is the darned starter in FS9 always runs regardless of>whether the engine has failed, the battery is off etc etc when>it is assigned to a key or button, so by "grabbing" the input>away from the computer and filtering it through an XML gauge,>I can prevent this.>>SteveStarters have been fixed in FS X.

Share this post


Link to post
Share on other sites

2 years later...............:(I would argue that statement is wrong, "fixed starter in FSX" depends upon you point of view. Regardless, I have written my own starter logic, fuel logic and mixture control logic for FSX that completely bypasses the screwed FSX logic as it applies to helicopters. This way I can control the helicopters engine parameters according to the way they SHOULD work as opposed to utilizing whatever FSX tries to default to.Steve

Share this post


Link to post
Share on other sites

>2 years later...............:(>>I would argue that statement is wrong, "fixed starter in FSX">depends upon you point of view. Patrick was referring to the "broken" TOGGLE_STARTER that didn't... "toggle" that is. In FS2002/4 the key event acted like a momentary switch, when in fact it "should have" (according to ACES' logic) acted as a toggle switch, hence the name... ;)Frankly, I would have preferred they change the name and leave it as a momentary contact switch, but that's just my opinion. :-wave NOTE: Would folks please turn off the bloody "plain text" option unless they're posting code snippets? :-rotor

Share this post


Link to post
Share on other sites

Yup Patrick was correct, and I also wish they had not changed the way the starter works, but oh well, onwards and upwards.Steve

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