Sign in to follow this  
Rocky

send_key_event

Recommended Posts

In the FS9 SDK, the "send_key_event" function appeared in addition to the existing "trigger_key_event". I tested it and saw no difference between these functions.Does someone know the difference?Do you know how events can be triggered without fooling the FS auto-repeat mode?Thanks for any clue.Eric

Share this post


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

Salut Eric,not sure I understand the question - what do you mean by triggering events, trigger a key press event?

Share this post


Link to post
Share on other sites

I believe I made a post about this a few months ago, but you are correct in the fact that send_key_event should not trigger the key repetition.:-) Edit: Can't find that post, so I guess I never actually posted it. :dunce:

Share this post


Link to post
Share on other sites

Etienne,You're right, I would like to trigger an event, without triggering a key. For example, there is a stall protection in the Airbus aircrafts: when the incidence angle is too high, full throttle power is automatically applied. This can be done easily by using the trigger_key_event (or send_key_event), something like:trigger_key_event(KEY_THROTTLE_TO_GA, 0);The problem when you do so is that the auto-repeat system of FS believes you are constantly repeating a key press, so the auto-repeat is engaged, and if you try to increase the AP heading or the VOR course, it increases 10 by 10 degrees instead of 1 by 1.I would like to avoid this.Eric

Share this post


Link to post
Share on other sites

I am only used to XML but a checking logic could avoid this:If stall protect is active AND Throttle is NOT at TOGA if{KEY_THROTTLE_TO_GA} (A:AUTOPILOT TAKEOFF POWER ACTIVE, bool)(>K:AUTO_THROTTLE_TO_GA)Regards,Roman(KGRB)[body vlink=#777c8e" alink="#777c8e][table border=0" cellpadding="0" cellspacing="0" width="240" bgcolor="#777c8e" height="95][tr][td width=20" height="95][table border=0" cellpadding="0" cellspacing="0" width="20" height="95][tr][td]http://home.new.rr.com/spokes2112/images/blank.jpg[/td][/tr][tr][td]http://home.new.rr.com/spokes2112/images/blank.jpg[/td][/tr][tr][td][a href=http://www.wheelchairaviators.org]http://home.new.rr.com/spokes2112/images/button.jpg[/a][/td][/tr][tr] [td][a href=http://www.packers.com]http://home.new.rr.com/spokes2112/images/button.jpg[/a][/td][/tr][tr] [td][a href=http://www.eaa.org]http://home.new.rr.com/spokes2112/images/button.jpg[/a][/td][/tr] [/table][/td][td width=200]http://home.new.rr.com/spokes2112/images/test.gif[/td][td width=20" height="95][table border=0" cellpadding="0" cellspacing="0" width="20" height="95][tr][td]http://home.new.rr.com/spokes2112/images/blank.jpg[/td][/tr][tr][td]http://home.new.rr.com/spokes2112/images/blank.jpg[/td][/tr][tr][td][a href=http://www.friendsofcrivitzairport.com]http://home.new.rr.com/spokes2112/images/button.jpg[/a][/td][/tr][tr] [td][a href=http://www.microsoft.com/games/flightsimulator/]http://home.new.rr.com/spokes2112/images/button.jpg[/a][/td][/tr][tr] [td][a href=http://www.fltplan.com]http://home.new.rr.com/spokes2112/images/button.jpg[/a][/td][/tr] [/table][/td][/tr][/table][/body]

Share this post


Link to post
Share on other sites

Roman,This is a nice workaround, which works in this specific case that I used as an example. But for more complex cases, it doesn't work. In fact, I have fully reprogrammed a new autothrottle that adjusts throttle all the time by using the THROTTLE_SET events. The value is always recomputed and applied using trigger_key_event or send_key_event. As the computed value is different each time, your solution does not work here.My autothrottle works fine, but fools the FS auto-repeat...Thanks for your help !!Eric

Share this post


Link to post
Share on other sites

replace all trigger_key_event by send_key_event.Also avoid using INC/DEC style events. Use SET events.I have custom autopilot and fadec that sends events in about every cycle and controls such as altitude selector and others not accelerates at all."Fix control acceleration" in FSUIPC was set off to be sure that everething is fine :)

Share this post


Link to post
Share on other sites

In general, under windows, if you need to send a particular event to your code without having to use keys, one method is to hook the message loop and send yourself a particular message when the conditions are right. This can trigger a response from one or more listeners in your code. There is a battery of functions in the API that may help you in this regards - look for the SetWindowsHookEx () routine - you can hook messages, keyboard, etc...You can also trap windows keys via low level hooks, and ensure that FS never sees the key that was pressed (or DirectInput for that matter). I use that in some forthcoming gauge project. The premise that if FS never sees the key, but you know about it, you really don't care what FS's keyboard handling routine may or may not do with it since you just pre-empted it. I have some sample code I could share with you if you're interested.

Share this post


Link to post
Share on other sites

Hello Etienne,Thanks for your help. I know the solution of using DirectInput tp trap the key events so that FS never sees it. It works fine, but... the problem I have here is that I don't know what key I should trap. For example, imagine that I want to trap the key used to automatically start the engine. You may think I should trap the Control-E key, but this will not work if the user changes its key assignment in FS. So how can I make sure I trap the right key?Eric

Share this post


Link to post
Share on other sites

Have you tried to capture the engine start key with XML then writing to a L: var that can be read back by both C and XML?Something like: 1 (>L:auto_start) (Not 100% sure about the syntax)Arne Bartels

Share this post


Link to post
Share on other sites

No, I have never tried this before because I wanted to avoid the use of XML. But if this is the only solution, I will do this.Thanks.Eric

Share this post


Link to post
Share on other sites

Not the only solution, but an easy way without DInput and with automatic key interpretation. On the other hand it is only a kind of "peeking" and the event is carried out nevertheless. I don't know if it is what you look for.Arne Bartels

Share this post


Link to post
Share on other sites

Hi,maybe as a workaround you could trigger the key_event via a timer, like:if(stall_protection == 1)wait_trigger ++;if(wait_trigger > 0 && wait_trigger < 2)trigger_key_event(KEY_THROTTLE_TO_GA, 0);if(wait_trigger > 18)//stop the timerwait_trigger = 18;on reset of the protection loop, reset also the timer:if(stall_protection == 0)wait_trigger = 0;Another way would be to trigger the key_event only once per second, or as often as you want, like this:MODULE_VAR tick18 = {TICK18};lookup_var(&tick18);if((int)tick18.var_value.n % 18 == 0)//once per secondtrigger_key_event(KEY_THROTTLE_TO_GA, 0);I hope this will help,Chris Koegler

Share this post


Link to post
Share on other sites

You're right, Arne, this is not exactly what I am looking for because the event is carried out anyway. I would like to catch it and block it so that FS never recives it. As far as I know, this can only be done by using DirectInput.In your post #19532 (key access for XML gauges), I thought that blocking the key event was possible, but I couldn't access the example attached.Let me tell you why I want to use this. The problem is that I would like to be able to arm the spoilers when the aircraft is on ground so that they are automatically extended in case of a ejected take off. If you do this when the engines are on IDLE position (for example when you hold position before entering the runway), FS sees that you are on the ground, so the spoilers are extended as soon as you arm them. I would like to avoid this by catching the SPOILER ARM event and keep it for myself (for an internal flag), so that the spoilers don't extend when I am waiting on the taxiway.If you have another solution for this problem, I would be glad to know it...Eric

Share this post


Link to post
Share on other sites

In this case wouldn't it be easier to use an entirely different key (combination) for your purpose, read with DInput? Maybe configurable via an ini-file or similar? Instead of "stealing" a key from FS processing just instruct the user to avoid using the FS key "arm spoiler" on ground and use a different key instead. Even button assignments to joysticks are readable without much problems via DInput.I can't recall exactly to remove the keys from FS via DInput, but I resorted to a key combination not used by FS and no key removing. In the end a lot easier.The XML method is good for preinterpreted keys (On Event=...), action via key, button, mouse or gauge are treated the same, but for "raw access" in exclusive mode (On Key=...)it's a bit difficult. Good for "keyboard" style inputs (e.g. GPS waypoint names), but for "new events" you have to get around the problem, that all keys are exclusive to XML and FS doesn't see them anymore. I havn't tried to use single keys (e.g. On Key="K") though, maybe you can introduce new events this way.Arne BartelsP.S. there are some interesting new functions in the "lower regions" of fs9gauges.h e.g. register_key_event_handler, but I have no idea how they are supposed to work.

Share this post


Link to post
Share on other sites

E.g. this works for a new event:0 (>K:SLEW_TOGGLE)Only key "K" is accessed no "lockout" of other keys.But only if the gauge is "visible".Arne Bartels

Share this post


Link to post
Share on other sites

That's interesting. I saw those functions in fs9.h but didn't try to understand how they work yet. I am now working on a completely different way of solving this problem.Thanks for your help anyway !!Eric

Share this post


Link to post
Share on other sites

this function can intercept events but it can't filter them.In other words you will able see event, but FS will see it too.I have checked assembly after return from callback. FS not verifyes return value.

Share this post


Link to post
Share on other sites

>That's interesting. I saw those functions in fs9.h but didn't>try to understand how they work yet. I am now working on a>completely different way of solving this problem.If you are building the model as well as programming the gauges, why not create your very own "spoilers" command variable using embedded XML code in the .mdl file?With this method, control of the "spoilers" is accessible only via a custom XML L:varible and may be controlled either by an XML gauge or a C gauge...

Share this post


Link to post
Share on other sites

This is also an interesting option, but unfortunately it is not possible here as I am not the designer of the model.Thanks for the info !!Eric

Share this post


Link to post
Share on other sites

Hello _ak,This function is very interesting for many purposes, but I can't use it, it crashes FS as soon as I use it. Here is the code I used:static int CatchKeyEvent(ID32 event, UINT32 evdata, PVOID userdata){ ... return 0;}and in my initialization function:...register_key_event_handler(CatchKeyEvent, NULL);...I can't find what is wrong here ?!?Thanks for any help !!Eric

Share this post


Link to post
Share on other sites

Hi Eric,the import functions in the gauge callback is not documented (imagine that), an my past experience with those is that it crashes, probably because this is something you need to "hook and pass", meaning, you can't just grab it - the previous handler needs to be called in the chain.One sure way to prevent FS from getting keys is by using a keyboard hook event using the SetWindowsHookEx API call. This grabs windows virtual keys (and associated scan codes for brake or make), and you get to select if you want the key to be passed on or not.This will not crash FS and can be quite efficient at filtering keys, and unlike DX, no issues preventing the key from being processed by another listener registered by the same handle (which you share with FS since the gauge file runs in the same handle space).I have not looked at how, or where FS stores keyboard mappings (registry, cfg file or other), but I'm pretty sure that if you just map CTRL-E, and prevent FS from seeing it by the above method, no-one will complain much, and if they try an autostart, I'd just kill the fuel flow in code which will also kill the autostart sequence (=, set the mixture axis to minimum). Oh, and all this help comes with a "free" panel my Mr. Marciano right?

Share this post


Link to post
Share on other sites

As I have already answered to this kind of suggestion, the problem with the solution you propose here is that I can catch CTRL-E key, but if the user has changed hs key assignment, it will not work. This is why I wanted to use the event handler function to catch the key related to the event, whatever it is.Regarding your last question, all the questions asked here are for my personal knowledge. This knowledge is globally used for both freeware and payware projects. Don't worry, I will release a new freeware version of my Airbus panels that will take advantage of all these things learned, the only question is WHEN. I'm still running after time...Eric

Share this post


Link to post
Share on other sites

>This function is very interesting for many purposes, but I>can't use it, it crashes FS as soon as I use it. Here is the>code I used:>>static int CatchKeyEvent(ID32 event, UINT32 evdata, PVOID>userdata)>{> ...> return 0;>}Change it to

static int FSAPI CatchKeyEvent(ID32 event, UINT32 evdata, PVOID userdata)

Don't ask why MS forgot to write calling convention to sdk.

Share this post


Link to post
Share on other sites

FSAPI missing is "business as usual" for FS SDKs. Didn't surprise me, I didn't have time to check for myself, but inserting "FSAPI" (defining the calling convention) was also my first thought.Arne Bartels

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