Jump to content
Sign in to follow this  
x-alberto

Command rewrite

Recommended Posts

A sample script demonstrating command rewrite

It will create a custom command "SPECIAL/buttons/trim_shift"

If you map a key or joy button to this command, it will change the default behavior of standard commands:

 sim/view_pan_up

 sim/view_pan_down

 sim/view_pan_right

 sim/view_pan_left

so that

 

 pitch_trim_up

 pitch_trim_down

 aileron_trim_left

 aileron_trim_right

will be invoked instead

It should work with any aircraft, provided that no other plugin is doing a command rewrite

I use this so that my joystick's HAT switch works both to move the view or to trim...

Note: there is probably some useless (or bad!) code in it... feedback is welcome


--[[

Command rewrite, v 1.0

by x-alberto (www.x-plane.it), 2011



HAT swith remapping to pitch and roll trim

(very experimental)



If you find Gizmo useful, please make a donation to its author: br@x-plugins.com

--]]









g_is_shift_trim  = 0

g_is_view_up     = 0

g_is_view_down   = 0

g_is_view_right  = 0

g_is_view_left   = 0



-- create a custom command for "shifting"

xp.newCommand("SPECIAL/buttons/trim_shift", "trim_shift", "trim_shift" )



-- if a command already exists, it apperars that "xp.newCommand" creates a hook instead

xp.newCommand("sim/view/pan_up",    "View Up",    "view_pan_up" )

xp.newCommand("sim/view/pan_down",  "View Down",  "view_pan_down" )

xp.newCommand("sim/view/pan_left",  "View Left",  "view_pan_left" )

xp.newCommand("sim/view/pan_right", "View Right", "view_pan_right" )





function main()



 -- nothing to do here



end





function OnDraw_Windows()



 -- nothing to do here as well



end



-- fun starts here...



function trim_shift_OnStart()

 --button or key press started

 g_is_shift_trim=1

end



function trim_shift_OnHold()

 --button or key is being held down

 g_is_shift_trim=2

end



function trim_shift_OnStop()

 --button or key was released

 g_is_shift_trim=0

end











function view_pan_up_OnStart()

 --button or key press started

 g_is_view_up=1



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/pitch_trim_up" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_up_OnHold()

 --button or key is being held down

 g_is_view_up=2



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/pitch_trim_up" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_up_OnStop()

 --button or key was released

 g_is_view_up=0



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandEndByName( "sim/flight_controls/pitch_trim_up" )

   return 1 --prevent x-plane from processing the command

 end



end





function view_pan_down_OnStart()

 --button or key press started

 g_is_view_down=1



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/pitch_trim_down" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_down_OnHold()

 --button or key is being held down

 g_is_view_down=2



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/pitch_trim_down" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_down_OnStop()

 --button or key was released

 g_is_view_down=0



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandEndByName( "sim/flight_controls/pitch_trim_down" )

   return 1 --prevent x-plane from processing the command

 end



end





function view_pan_left_OnStart()

 --button or key press started

 g_is_view_left=1



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/aileron_trim_left" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_left_OnHold()

 --button or key is being held down

 g_is_view_left=2



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/aileron_trim_left" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_left_OnStop()

 --button or key was released

 g_is_view_left=0



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandEndByName( "sim/flight_controls/aileron_trim_left" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_right_OnStart()

 --button or key press started

 g_is_view_right=1



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/aileron_trim_right" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_right_OnHold()

 --button or key is being held down

 g_is_view_right=2



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandBeginByName( "sim/flight_controls/aileron_trim_right" )

   return 1 --prevent x-plane from processing the command

 end



end



function view_pan_right_OnStop()

 --button or key was released

 g_is_view_right=0



 if g_is_shift_trim == 0 then

   return 0 --let x-plane process the command

 else

   xp.commandEndByName( "sim/flight_controls/aileron_trim_right" )

   return 1 --prevent x-plane from processing the command

 end



end

  • Upvote 1

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×