Jump to content
Sign in to follow this  
phjvh

key access for XML gauges

Recommended Posts

Guest bartels

Some time ago I was asked how to access keystrokes by XML gauges. The only answer I could have given, would be to build a C-gauge using Dinput and passing to L: variables. But recently I discovered something new in the GPS codes: there is a genuine key access section in the XML possible, even simpler as in C the .. section. I was searching for something completely different ( "Can the C:fs9gps:... syntax also used in C? In the other direction: Can TrafficInfo be read from XML?"), but I found this.In the Keys section two different accesses can be made, a "processed keys" or "listen" mode, where the keypresses, joystick buttons and gauge actions are preprocessed and mapped to the corresponding (K:...) actions ( ... ), the "Event" is still executed.The second method is direct keyboard access where you "steal" the raw codes away from FS. The raw method only works if the section is "visible", the gauge itself has to be visible, and optionally also a section in the Section (NOTE gauges in the VC are always visible, in the 2D panel only if their panel window is visible). To the example:Slaving the Aircraft exit to the AP switch is pretty dump, but it's for demonstrating purposes. The second example reads the last pressed key and draws it to a string of four characters. First the keyscan has to be activated by clicking on the gauge. Since L: vars can't hold strings, the numeric values are stored in one L: variable per char and then displayed.Arne Bartels

Share this post


Link to post
Share on other sites
Guest Eugen

Arne,Is the string converted into a numeric value by fs9 or must that be done xml?Hmm could this give the possibility to develop a flight computer unit where the buttons could be connected to the keyboard?BrgdsEugenPs I think that this post should go into the FAQ as a valuable knowledge

Share this post


Link to post
Share on other sites
Guest bartels

The keyscan code itself is "(M:Key)". I shifted all other chars before, then store it with "(>L:char1,number)". "(M:Key) chr" would convert the keycode to the corresponding char, but L: can't hold chars and strings, so I do the conversion only for the display (multiple use of "chr"). The both lines have the same effect, but do something different, the first, commented one, just displays the last four scancodes as four chars ("!s!....!s!"). The second version converts the scancodes to chars ("chr") and then adds them to a complete string one by one ("scat"), at last the complete string is displayed ("!s!"). BTW the inverse to "chr" is "ord".A bit complicated, but OK I think. Arne Bartels

Share this post


Link to post
Share on other sites

Hi Arne,Well, this is another great discovery ...LOLI have a question, and an addition.The question:The "raw" method (using M:Key) only works for normal Ascii keys.So no Shift- , or Control- sequences, or functionkeys like F1.Right ??Moreover, typing such a key in "raw" mode (like "g" or "p") is really "intercepting" it, so the corresponding FS function ("toggle gear" resp. "pause" ) is not executed.Right ??If both right, this means that, before you are able to use this "raw" method to control XML gauges, you have to use another method first to enable/disable this "raw" mode, otherwise all normal Ascii keys to control normal FS functions (like "g" for "toggle-gear") would be disabled permanently.Like you did with the condition in your example.The addition:The "listen" mode (using the On-Event method) is a great enhancement by itself.Upto now, I used "unused" FS events to control XML gauges. However, in FS9 this has a big disadvantage, since FS9 ignores events that are not relevant for that specific aircraft.E.g. using "toggle-afterburner4" as a control event (and reading the corresponding variable to see when the event has been given) cannot be used if the aircraft has no afterburner defined, or has no 4-rth engine.However, the "listen" method DOES allow this !!!!Example:Assume you have a one-engine aircraft with NO afterburner defined.With this "listen" method you can now (mis-)use AfterburnerEngine4 to control something in a XML gauge.In the XML gauge:(>K:TOGGLE_AIRCRAFT_EXIT)In the FS9.cfg (keys section)TOGGLE_AFTERBURNER4=51,11 //Assign "Control-Shift-3" to Toggle_Afterburner4Now, typing "Control-Shift-3" will toggle the Exit.(as in your example, not very usefull ... but just to illustrate the method).Cheers, Rob Barendregt

Share this post


Link to post
Share on other sites
Guest Skymed

Exciting stuff.I am trying to prevent the starter from operating when the battery is off. If the starter in a turboprop is assigned to a key , it always works and activates the default sound even with no power to the panel.So here is my attempt at doing that, but it locks up the flightsim. What did I do wrong??(A:Electrical master battery,bool) %BATTERY (%((A:Electrical master battery,bool))%{if}ON%{else}OFF%{end})(K:TOGGLE_MASTER_BATTERY,bool) ! (>K:TOGGLE_MASTER_BATTERY,bool)(L:key_track, bool) ! (>L:key_track, bool) (>K:TOGGLE_STARTER1) (L:key_track, bool) (L:char3,number) (>L:char4,number) (L:char2,number) (>L:char3,number) (L:char1,number) (>L:char2,number) (M:Key) (>L:char1,number) Steve

Share this post


Link to post
Share on other sites

Another way to prevent "CRTL-E":(>K:ABORT)Not so funny....Jan"Beatus Ille Procul Negotiis"

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...