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!
Code:-- 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 end if ipc.testbutton(joy, btn) == test then time1 = time2 return true end ipc.sleep(20) end end function buttonpress(j, b, du) if ignorepress then ignorepress = false return end -- 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 ipc.control(65676) end else -- This was a single press, send VIEW LEFT ipc.control(65680) ignorepress = false end else -- This was a longer press, send VIEW FORWARD ipc.control(65674) end end -- Enable event on button being pressed (only) event.button(joy, btn, 1, "buttonpress")