• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

MSFS Hijack input events using B:Vars!

Messages
87
Country
egypt
Hello all,
After some grueling trial and error lasting several days, Wanted to share with you how I was able to use the new <inputEvents> to disconnect the built in sim code for throttle control and output user input (joystick and buttons) to an L:var instead of triggering key events directly.
The example is what I came up with for intercepting throttle input for engine 1 and outputting them to an L:Var (L:THROTTLE1_SET,number) which will take a value of 0~1 corresponding to 0~100% user input throttle.
This might not be the easiest or cleanest way , but worked for me:
in my interior.xml:
XML:
    <Component ID="loadFadec">
        <UseTemplate Name="Marwan_Custom_Fadec">
        <THROTTLE_ID>1</THROTTLE_ID>
        </UseTemplate>      
    </Component>
   
       
   
    <Template Name="Marwan_Custom_Fadec">
        <Parameters Type="Default">
            <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
        </Parameters>
        <UseTemplate Name="ASOBO_Interaction_Base_Template">
            <USE_INPUT_EVENT_ID>ENGINE1</USE_INPUT_EVENT_ID>
        </UseTemplate>
    </Template>

        <InputEvent ID="ENGINE1">
            <Presets>
            <Extend Target="ASOBO_GIE_Anim_Handling">
                <Parameters Type="Default">
                    <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
                </Parameters>
            </Extend>
            <INPUT_EVENT_ID_SOURCE>ENGINE1</INPUT_EVENT_ID_SOURCE>
            <Preset ID="ENGINE1_Throttle_#THROTTLE_ID#">
                            <INCREMENT>0.1</INCREMENT>
                            <UPPER_LIMIT>16384</UPPER_LIMIT>
                            <LOWER_LIMIT>(A:THROTTLE LOWER LIMIT, position 16k)</LOWER_LIMIT>
                            <INIT_CODE>(A:GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#, position 16k) 16384 / s0 (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</INIT_CODE>

                        <Tooltip>
                            <Icon>MOVE_AXIS_Y</Icon>
                            <Interaction>PRIMARY_DOWN+Y_AXIS</Interaction>
                            <InteractionLockable>Y_AXIS</InteractionLockable>
                            <TTDescription RPN="True">@TT_Package.ENGINE_PUSH_TOGA_ACTION</TTDescription>
                            <TTValue RPN="True">(A:GENERAL ENG THROTTLE LEVER POSITION:1, percent) '%.1f%%' @sprintf</TTValue>
                        </Tooltip>  
                        <Value>
                            <Units>percent</Units>
                            <Code>(O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Code>
                            <Init>(A:GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#, position 16k) 16384 / (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Init>
                            <WatchVars>
                                <Simvar ID="GENERAL ENG THROTTLE LEVER POSITION:#THROTTLE_ID#"/>
                            </WatchVars>
                        </Value>
                        <Inc>
                            <Code>(L:THROTTLE#THROTTLE_ID#_SET,number) p0 + (&gt;B:ENGINE1_Throttle_#THROTTLE_ID#_SET)</Code>
                            <Parameters>
                                <Param Type="Float" RPN="True">p0</Param>
                            </Parameters>
                            <Bindings>
                                <Binding EventID="THROTTLE_INCR"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                    <Param>0.1</Param>
                                </Binding>
                                <Binding EventID="THROTTLE_INCR_SMALL"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                    <Param>0.05</Param>
                                </Binding>
                                <Binding EventID="THROTTLE#THROTTLE_ID#_INCR">
                                    <Param>0.1</Param>
                                </Binding>
                                <Binding EventID="THROTTLE#THROTTLE_ID#_INCR_SMALL">
                                    <Param>0.05</Param>
                                </Binding>
                            </Bindings>
                        </Inc>
                        <Dec>
                            <Code>(L:THROTTLE#THROTTLE_ID#_SET,number) p0 - (&gt;B:ENGINE1_Throttle_#THROTTLE_ID#_SET)</Code>
                            <Parameters>
                                <Param Type="Float" RPN="True">p0</Param>
                            </Parameters>
                            <Bindings>

                                        <Binding EventID="THROTTLE_DECR"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                            <Param>0.1</Param>
                                        </Binding>
                                        <Binding EventID="THROTTLE_DECR_SMALL"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                            <Param>0.05</Param>
                                        </Binding>
                                        <Binding EventID="THROTTLE#THROTTLE_ID#_DECR">
                                            <Param>0.1</Param>
                                        </Binding>
                                        <Binding EventID="THROTTLE#THROTTLE_ID#_DECR_SMALL">
                                            <Param>0.05</Param>
                                        </Binding>

                            </Bindings>
                        </Dec>
                        <Set>
                            <Code>p0 0 max 1 min s0 (&gt;L:THROTTLE#THROTTLE_ID#_SET,number) l0 (&gt;O:ENGINE_Throttle_#THROTTLE_ID#_Position)</Code>
                            <Parameters>
                                <Param Type="Float" RPN="True">p0</Param>
                            </Parameters>
                            <Bindings>
                                <!-- Aliases -->
                                <Binding Alias="ENGINE1_All_Throttle_Full_Forward"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                    <Param>1</Param>
                                </Binding>
                                <Binding Alias="ENGINE1_All_Throttle_Full_Backward"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                    <Param>0</Param>
                                </Binding>
                                <Binding Alias="ENGINE1_All_Throttle_Idle"><!-- event manipulating all throttles (declared for each throttle preset) -->
                                    <Param>0</Param>
                                </Binding>
                                <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Full_Forward">
                                    <Param>1</Param>
                                </Binding>
                                <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Full_Backward">
                                    <Param>#LOWER_POSITION_PCT_OVER_100#</Param>
                                </Binding>
                                <Binding Alias="ENGINE1_Throttle_#THROTTLE_ID#_Idle">
                                    <Param>0</Param>
                                </Binding>
                                <!-- EventIDs -->
                                <Binding EventID="THROTTLE_FULL">
                                    <Param>1</Param>
                                </Binding>
                                <Binding EventID="THROTTLE_CUT">
                                    <Param>0</Param>
                                </Binding>
                                <Binding EventID="THROTTLE#THROTTLE_ID#_FULL">
                                    <Param>1</Param>
                                </Binding>
                                <Binding EventID="THROTTLE#THROTTLE_ID#_CUT">
                                    <Param>0</Param>
                                </Binding>
                                <Binding EventID="THROTTLE#THROTTLE_ID#_SET">
                                    <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                                </Binding>
                                <Binding EventID="THROTTLE#THROTTLE_ID#_AXIS_SET_EX1">
                                    <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                                </Binding>
                                <Binding EventID="AXIS_THROTTLE#THROTTLE_ID#_SET">
                                    <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                                </Binding>
                                <Binding EventID="THROTTLE_SET">
                                    <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                                </Binding>
                                <Binding EventID="THROTTLE_AXIS_SET_EX1">
                                    <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                                </Binding>
                                <Binding EventID="AXIS_THROTTLE_SET">
                                    <Param Type="Float" RPN="True">p1 16384 / 1 + 0.5 *</Param>
                                </Binding>
                            </Bindings>
                        </Set>
                       
            </Preset>
            </Presets>
        </InputEvent>
 
Last edited:
Messages
87
Country
egypt
the same value is output in both (L:THROTTLE1_SET,number) and (B:ENGINE1_Throttle_1) and both can be used ,But I am more old school so I like working with L:Vars, I understand them better.
 
Messages
176
Country
unitedkingdom
the same value is output in both (L:THROTTLE1_SET,number) and (B:ENGINE1_Throttle_1) and both can be used ,But I am more old school so I like working with L:Vars, I understand them better.
Excellent!
I've briefly tested this gauge with your code on the freeware F-35B, it seems to work fine.

Code:
<Gauge Name="SpoilerThrust" Version="1.0">
<Comment>
</Comment>

<Update Frequency="10"/>

<Element>
  <Select>
    <Value>
(A:SPOILERS HANDLE POSITION, percent) 163.84 * (L:THROTTLE1_SET,number) * (>K:THROTTLE2_SET)
(A:SPOILERS HANDLE POSITION, percent) -1 * 100 + 163.84 * (L:THROTTLE1_SET,number) * (>K:THROTTLE1_SET)
    </Value>
  </Select>
</Element>

</Gauge>
 
Messages
1
Country
portugal
Maran, I just want to thank you for your code. I use it in my mod to give a persistent engine wear multiplier to thottle and it worked like a charm.
Thanks again!
 
Messages
244
Country
unitedkingdom
Sorry to necro/hijack this thread but the interwebs are full of the most complicated gobbledegook about MSFS 'input event' capturing which seem to bundle together lots of things including model interactions, tooltips and all sorts of stuff nothing really to do with the event capturing.

How many lines of XML does it take to do the absolute minimum - (i) when an event occurs (ii) execute a bit of XML RPN. I'd *really* prefer not to use a 10,000 line nested set of templates just to do this.
E.g.

"FLAPS_INCR" occurs

execute this RPN code:

(L:MYVAR) 123 + (&gt;L:MY_OTHER_VAR)

For me to capture the event you really don't need to know what I'm doing with any animations, or what I may or may not do with tooltips, or why my RPN code is what it is, or how I've implemented flaps on my plane or, crucially, why I really do want to use 10,000 lines of Asobo template code even though I don't realise that.

If there's a really simple answer to the above (it seems like there should be), is there another line that can be added that stops the propagation of the event to the sim such that the sim engine wouldn't change all the flap simvars?

thanks -B21
 
Messages
494
Country
austria
XML:
from an old file used in FS9, FSX and P3D before XMLTools


  <Macro Name="MCRFlapsRange">
   16384 (A:FLAPS NUM HANDLE POSITIONS,number) /
  </Macro>



<!-- Flaps Key Catcher *** Flaps Key Catcher -->
  <Keys>
    <On Event="FLAPS_INCR">
      (L:CORE5_FLAPS_Handle_Index,number) @MCRFlapsRange * (&gt;K:FLAPS_SET)        <!-- blocks flaps movment -->

      (P:ACTIVE VIEW MODE,number) 3 !=
      (L:CORE5_FlapsLever_PrePos,number) 7 &lt;
      &amp;&amp;
      (L:DSD_TECH_Knob2_SD,number) 0 ==
      &amp;&amp;
      (L:ThrQ_FlapsLever_in_Use,bool) !
      &amp;&amp;

      (L:OverH_Alt_Flaps_SW,bool) 1 ==
      (L:CORE5_Flaps_Action,number) 0 ==
      &amp;&amp;
      (L:OverH_Alt_Flaps_SW,bool) 0 ==
      ||
      &amp;&amp;
      if{
        (L:CORE5_FlapsLever_PrePos,number) ++ (&gt;L:CORE5_FlapsLever_PrePos,number)

        (P:ABSOLUTE TIME,seconds) (&gt;L:CORE5_Flaps_Req_Timer,seconds)
        1 (&gt;L:CORE5_Flaps_Action,number)

        1 (&gt;L:DSD_TECH_Knob2_SD,number)
        }
    </On>




<!-- blocks flaps movment -->
To prevent any action from FLAPS_INCR you have to send    a proper value to "(&gt;K:FLAPS_SET)"

in my case this  value is stored ad  (L:CORE5_FLAPS_Handle_Index,number)  for example 2
my plane has an (A:FLAPS NUM HANDLE POSITIONS,number)  of 7

(L:CORE5_FLAPS_Handle_Index,number) @MCRFlapsRange * (&gt;K:FLAPS_SET)  
            2                        16384   7    /    *    4681   (&gt;K:FLAPS_SET)  

(L:CORE5_FLAPS_Handle_Index,number) must adapted by yourself!

---------------------------------------------
some flaps variablen

                     7
   16384 (A:FLAPS NUM HANDLE POSITIONS,number) / 2340

   (A:FLAPS NUM HANDLE POSITIONS,number) are from 0 to 7

   40 30 25 20 15 5 2 0 8 (A:FLAPS HANDLE INDEX,number) case (&gt;L:CORE5_Handle_Position,degree)
 
Messages
407
Country
ca-britishcolumbia
Thanks to the OP for posting this. I really struggled with this until seeing this thread. I need to block and/or modify default flight surface inputs to model a complex hydraulic system and this code should get me going in the right direction.
 
Top