Jump to content
The simFlight Network Forums

[Lua] Scan controller buttons from Lua on startup / auto


Matthew Twomey

Recommended Posts

Looking for the easiest way to get the button state from a controller in a lua script that I'm running as "Auto" when FSUIPC starts up. My code is working, but things don't fall into place until I put some input on the controller I'm mapping. As soon as I provide any input - everything starts acting as expected.

I tried using the initreport from com.openhid, but I may not be doing this right. Here's what I'm at with this:

handle, rd, rdf, wr, initreport = com.openhid(0x04D8, 0x8A3D);

for i = 0, 3, 1 do
    local state = com.testhidbutton(handle, i, initreport);
    if (state) then
        ipc.log(i .. ": on");
    else
        ipc.log(i .. ": off");
    end
end

Regardless of the actual button state (actual physical switches in my case), all buttons come back as false, until I trigger any button - at which point they all immediately start reporting correctly. Is there a way to force it to "scan" the controller, or maybe I'm just doing it wrong?

Link to comment
Share on other sites

Ok - this seems to take care of it:

handle, rd, rdf, wr, initreport = com.openhid(0x04D8, 0x8A3D);
initreport = com.readreport(handle, 0);

for i = 0, 3, 1 do
    local state = com.testhidbutton(handle, i, initreport);
    if (state) then
        ipc.log(i .. ": on");
    else
        ipc.log(i .. ": off");
    end
end
ipc.log("val1: " .. com.gethidbuttons(handle, initreport));

I'm not sure if that com.readreport is the right approach, but it's working. If anyone has a thought on this, please share.

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.