MobiFlight Community Support

Welcome to the forum for MobiFlight! Feel free to reach out to the community in case you have questions, issues or just want to share great ideas or details about your latest home cockpit project.

You like MobiFlight? Donate via PayPal and support the MobiFlight development. Thanks! 

Posts: 14
I'm building out a G1000 button box. The CLR (clear) button has two states short press and long press and are mapped to two different MSFS2020 events
G1000 PDF
-> AS1000_PFD_CLR
-> AS1000_PFD_CLR_Long

how can I simulate this with a single button? Should I map this to a joystick then do a lua script or is there an easier way?
2021-05-28 21:42
From: ETSI, Germany
Posts: 4647

I think your right.
For the moment i not see a way to build this within mobiflight (Counter or duration detection)
(I need to talk to Sebastian if this is maybe a option for a future release.... but i don´t think thats a easy patch. This would need may a bigger rework of logics)

So lets figure out your options for now (or for ever if this is not a feature Seb. like to build in MF)

1. Electrical or with a second external Controller. ( Difficult and not so comfortable)
There should be a way to use electrical Elements or a second Arduino ( e.g. a little nano/micro with a own written sketch) that split the Switch into TWO (or more) Pins....
Means... If you Press and release within short time it send a signal on Ouput line 1..... IF you make a otherwise a "hold" or a Long Press with more then e.g. 0,5 Sec) then it send a Signal on Output Line 2.

2. Via LUA Script !
But here i think we are not "bind" to a Joy Button..... We can use also MF to "fire" the script! Pretty sure via VJOY but i think it should also work by writing a Free Offset to 1/0 with the button..... As i understand for the Lua Script its no matter if it use a Real Joystick or VjoyButton or Offset for indication.

Please check the "TrippleUse.LUA" from the "Lua Example Files" included in the FSUIPC SDK.
-- Example of making a single button give three separate uses:
	-- To keep things relatively simple, here we deal with one
	-- specific button (defined as joystick 1, button 0 below).
	-- But you could generalise this and have multple buttons,
	-- each with multiple actions
	-- The multiple use is obtained by a simple method:
	  -- A short press and release (like a mouse click)
	  -- A double short press and release (like a double click)
	  -- A press held for longer (over half second)
	-- Just for a visible example which can be applied easily,
	-- here a single button is used to select left view, right
	-- and forward view, using FS controls. You could just as
	-- easily send keypresses or sequences of either.
	-- Single short press = left view (VIEW LEFT = 65680)
	-- Two short presses = right view (VIEW RIGHT = 65676)
	-- A longer press = frward view (VIEW FRWARD = 65674)

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

-- Function to time the button being pressed or left released
-- Allow only up to "interval" till decide no change
local function timebutton(test)
  while true do
		time2 = ipc.elapsedtime()
		if (time2 - time1) > interval then
			ignorepress = false
			return false
	 	if ipc.testbutton(joy, btn) == test then
			time1 = time2
			return true

function buttonpress(j, b, du)
	if ignorepress then
   	ignorepress = false
	-- Note time button was pressed
	time1 = ipc.elapsedtime()
	time2 = 0

	if timebutton(false) then
		-- First press / release counts: see if there's another
		if timebutton(true) then
			-- got another press in time, look for release
			if timebutton(false) then
				-- this was a double press, send VIEW RIGHT
			-- This was a single press, send VIEW LEFT
			ignorepress = false
		-- This was a longer press, send VIEW FORWARD

-- Enable event on button being pressed (only)
event.button(joy, btn, 1, "buttonpress")

If we "change" the variable from Joy and Button into e.g. a Offset then it should be possible also with MF. ( Or you use Vjoy for that)
Good Luck !
2021-05-29 12:25
Posts: 14
Awesome! thank you for taking the time to write a full how-to on this. I'll give this a try. I might look into the MF code and see if there is something I might be able to hack into. I was thinking a new tab under the button setup that allows for hold (similar to the press/release tabs) and then when you get button,0 start a counter until you see button,1 if < x short if >= x long.

I'm already using vjoy for and a macro for setting the heading bug to current so I'll do something similar.
2021-05-30 08:30
Posts: 14
I finally had a few minutes of free time. I added a tab to the button panel that allows for a long hold. It works more like if long held then released do X vs short hold do Z. I Think the best way would be to modify the Arduino code to monitor the press time and then send up a 3 instead of a 0/1 if the button is held for more than y ms. I might look into that next.
2021-06-10 01:22