Jump to content
The simFlight Network Forums

Can't Control TrackIR Thru LUA Keypresses


Recommended Posts

1. Included(but modified) "TripleUse.lua" works.

2. Made new lua for TrackIR-One button click for "CENTER", two for "PAUSE". Also wanted to automatically turn on "PRECISION".

3. TripleUse(for Panels 2,3,4) works fine, must be error in sending keypresses.

 

4. Bottom of FSUIPC4.ini looks like:

[Auto]

1=Lua 1But_F12-F11

2=Lua 1But_Panel-2-3-4

3=Lua SynAxis

 

5. 1But_F12-F11.lua looks like:

--  TrackIR Control

-- 1st, Turn "Precision Control ON"
ipc.keypress(F10)

-- Making a single button give two separate uses:
 
 
 -- 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)
 

 
 -- Single short press = F12 (TrackIR Center)
 -- Two short presses  = F11 (TrackIR Pause)

        -- Yoke, Right Side Red Button

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

-- 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
   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)
 -- Cancel event so we don't get called again for double press
 event.cancel("buttonpress")
 
 -- Note time button was pressed
 time1 = ipc.elapsedtime()

  -- 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 "Instrument/Panel #2"
    ipc.keypress(F11)
   end
           else 
   -- This was a single press, send "Instrument/Panel #1"
   ipc.keypress(F12)
  end

 -- Restore cancelled event
 event.button(joy, btn, 1, "buttonpress")
end

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

 

Thx In Advance

~ Matt

Link to comment
Share on other sites

1. Included(but modified) "TripleUse.lua" works.

2. Made new lua for TrackIR-One button click for "CENTER", two for "PAUSE". Also wanted to automatically turn on "PRECISION".

3. TripleUse(for Panels 2,3,4) works fine, must be error in sending keypresses.

 

Can you ask an actual question? I tried to read all this not knowing what I was looking for or why. It doesn't work, I've no idea what I'm looking at.

 

Please state precisely what your question is.

 

Pete

Link to comment
Share on other sites

Sorry Pete.

Can't get lua file to run. Want to control TrackIR(Centering View&Pausing it)using single CH Yoke button(joy 2, btn 1). FSX doesn't respond to the desired 2 TrackIR cmnds)when clicking this button. I've copied/modified a working lua that handles bringing up panels 2,3 or 4. This one works fine. The TrackIR lue(1But_F12-F11) doesn't. I must be sending keypress cmnd(s) wrong?? I've included listing of non-running TrackIR button press lua(for ur debugging?)

Hope this helps.

Thx In Advance

~ Matt

Link to comment
Share on other sites

Can't get lua file to run.

 

If it doesn't run the reason for it failing will be logged in the FSUIPC log file. Have you checked?

 

Just a quick look, I see this line

 

-- Function to time the button being pressed or left released

 

but there is no function. Later there is this line:

 

function buttonpress(j, b, du)

 

preceded by an "end" which doesn't seem to match anything starting!

 

Then these lines

 

 if timebutton(true) then

   -- got another press in time, look for release

   if timebutton(false) then

 

are calling a function which doesn't even exist.

 

Overall it looks a right mess.  I think you need to look at what you are doing before starting to edit things you don't understand. But at least do look in the Log for error messages, they'll tell you what the error is and where (i.e. which actual line).

 

Pete

 

 

 

Pete

Link to comment
Share on other sites

Thx Pete. Will try to learn lua prgm'ing.

Question: To send the keybd F12 key, should it be:

(a) ipc.keypress(F12)  -or- according to pg. 17 in "FSUIPC Lua Library.pdf":

( B) ipc.keypress(123)

 

123. The values is a keycode. I'm afraid I haven't put all the names of all the keys in -- some would be difficult in any case as they vary country to country.

 

Of course you can always name the ones you want to use yourself, like

 

F12 = 123

 

at the beginning. then you can use F12 instead.

 

Pete

Link to comment
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
×
×
  • 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.