Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Pete,

I am successfully using your "Triple Use.Lua" plug in with my CH Throttle Quad to have 36 functions using only the 6 toggle buttons. What I am now wondering is if it is somehow possible to use the "long press" to immitate the R function as described for programming buttons in FSUIPC. That is to say, "Repeat" the key press or control whilst the button is kept held down. For example, I have several buttons programmed to increase/decrease Hdg, Course, IAS, Altimeter, etc using the "Triple Use.Lua" plug-in, assigned to the "long press" portion. It would be great if one could get these to repeat until the button is released, as right now, when the "long press" is detected, the Alt, Hdg, Course, etc only change one unit at a time, meaning, for example, I would have to press and hold the same button 180 times to adjust from a heading of 180 to 360.

Jim

Posted
I am now wondering is if it is somehow possible to use the "long press" to immitate the R function as described for programming buttons in FSUIPC. That is to say, "Repeat" the key press or control whilst the button is kept held down.

Yes. You'd have to put a loop in for the longer press. Taking my original example:

		-- This was a longer press, send VIEW FORWARD repeatedly
		while ipc.testbutton(joy, btn) ~= 0 do
			ipc.control(65674)
			ipc.sleep(50) -- 50 = 20 repeats per second. Adjust to taste!
		end

or, better, to make sure you do get at least once instance (which the above doesn't guarantee)

		-- This was a longer press, send VIEW FORWARD repeatedly
		repeat 
			ipc.control(65674)
			ipc.sleep(50) -- 50 = 20 repeats per second. Adjust to taste!
		until ipc.testbutton(joy, btn) == 0

Regards

Pete

Posted

Pete,

I am using the following code:

joy = 0
btn = 6
interval = 500 -- 1/2 second press, gap, press limits

local function timebutton(test)
  while true do
		time2 = ipc.elapsedtime()
		if (time2 - time1) > interval then
			return false
		end
	 	if ipc.testbutton(joy, btn) == test then
			time1 = time2
			return true
		end
	 	ipc.sleep(20)
	end
end

function buttonpress(j, b, du)

	event.cancel("buttonpress")

	time1 = ipc.elapsedtime()

	if timebutton(false) then
		if timebutton(true) then
			if timebutton(false) then
				-- this was a double press
				ipc.macro("PMDG 1900:Prop Sync")
			end
  	else	
			-- This was a single press
			ipc.macro("PMDG 1900:Feather")
		end
	else
		-- This was a longer press
repeat		
ipc.macro("PMDG 1900:Altimeter Inc")
ipc.sleep(250)
until ipc.testbutton(joy, btn) == 0
end
	event.button(joy, btn, 1, "buttonpress")
end

event.button(joy, btn, 1, "buttonpress")

however, when I press and hold the button, the macro i.e. "PMDG 1900:Altimeter Inc" repeats, but does not stop when I release the button. The altimeter continues to increase despite releasing the button. It is as if the plug-in does not detect the button release.

Jim

Posted

      until ipc.testbutton(joy, btn) == 0

Oops! I forgot that "testbutton" returns a Lua BOOLEAN, either true or false. It is never 0 because it isn't a number in Lua (unlike in C which I normally use).

Try

       until not ipc.testbutton(joy, btn)

Regards

Pete

Posted

Pete,

...a work in progress... I don't suppose there is a way to add to the code you sent me to make the "long press" button run the same command in two different ways? For example, if I wanted to increase my heading, I could either press and hold the button and get a single degree increase, or I could continue to hold the button for just a bit longer and the "repeat" takes over, increasing the heading at a faster rate, kind of like a fine and course adjustment?

Jim

Posted
I don't suppose there is a way to add to the code you sent me to make the "long press" button run the same command in two different ways? For example, if I wanted to increase my heading, I could either press and hold the button and get a single degree increase, or I could continue to hold the button for just a bit longer and the "repeat" takes over, increasing the heading at a faster rate, kind of like a fine and course adjustment?

The easiest way would be to simply use a variable for the sleep:

      delay = 1000   --adjust first delay to taste
      repeat      
             ipc.macro("PMDG 1900:Altimeter Inc")
             ipc.sleep(delay)
             delay = 100  -- adjust repeat to taste
      until not ipc.testbutton(joy, btn)

Are you learning stuff this way? Time to try your next need yourself? ;-)

Pete

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.