XInput doesn't see controller inputs when not in focus Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Worst Username
Posts: 3
Joined: 25 Jan 2022, 21:32

XInput doesn't see controller inputs when not in focus

Post by Worst Username » 25 Jan 2022, 21:57

I have the same problem as Raygereio in viewtopic.php?t=40533.

evilC says that XInput solves it in viewtopic.php?t=61698, but it doesn't work for me.

I am using XInput for 1.1 from https://www.autohotkey.com/board/topic/35848-xinput-xbox-360-controller-api/.

Using Bluetooth Xbox Series X|S controller, the example script on the XInput page works perfectly even when not in focus, so XInput_GetState is working. But when I run this script,

Code: Select all

XInput_Init()
Joy1::MsgBox, A
it only works when the script window is in focus. Thankfully, UCR works for me, so if this can't be solved I could just use that. But I'd rather get this working and know how to use XInput for the future.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: XInput doesn't see controller inputs when not in focus  Topic is solved

Post by swagfag » 26 Jan 2022, 02:49

well why would u expect this example to behave any differently?
ure initting XInput - that just loads a DLL and fetches some function pointers from it
then ure back to using AHK's joystick functions, which are internally based on the Windows Multimedia API joystickapi.h(ie not DirectX's XInput)

i dont do joysticks, but what u need to do i think is write a loop that constantly checks the XInput state and dispatches keys accordingly. in other words, what the XInput example that works is already doing........

Worst Username
Posts: 3
Joined: 25 Jan 2022, 21:32

Re: XInput doesn't see controller inputs when not in focus

Post by Worst Username » 26 Jan 2022, 11:32

Is there any way to set it up to not constantly grab the state every 100ms? Would grabbing every 100ms take up computer resources? Is that how normal hotkeys work? I’m kind of new to this, and I don’t see why I can’t set it up to work like a normal hotkey.

Edit: Also, how does UCR.ahk detect controller input? Because that is working for me when not in focus.
Last edited by Worst Username on 26 Jan 2022, 12:14, edited 1 time in total.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: XInput doesn't see controller inputs when not in focus

Post by swagfag » 26 Jan 2022, 12:08

Worst Username wrote:
26 Jan 2022, 11:32
Is there any way to set it up to not constantly grab the state every 100ms?
its an editable script, just tweak the delay however u like
Would grabbing every 100ms take up computer resources?
anything u do with a computer takes up computer resources. this question doesnt make much sense
Is that how normal hotkeys work?
define "normal" hotkeys
I’m kind of new to this, and I don’t see why I can’t set it up to work like a normal hotkey.
im assuming u did read through the links u urself posted, so its because of:
evilC wrote:
04 Feb 2019, 06:02
AutoHotkey's GetKeyState() command no longer works properly on Windows 10 (As of 1809 or thereabouts) with non-xbox360 XInput controllers.
It will work fine while the AHK script is the active application, but as soon as you switch into a game, AHK will no longer be able to read the stick.
The solution is to use the XInput library
...allegedly

Worst Username
Posts: 3
Joined: 25 Jan 2022, 21:32

Re: XInput doesn't see controller inputs when not in focus

Post by Worst Username » 26 Jan 2022, 21:10

Sorry. I wasn't very clear about what I was asking. I wanted to know if this:

Code: Select all

XInput_Init()
Loop {
If State := XInput_GetState(0) {
If (State.wButtons&XINPUT_GAMEPAD_BACK) {
MsgBox, Back
}
}
Sleep, 100
}
would use any more resources (while idling) than this (normal hotkey):

Code: Select all

Joy7::MsgBox, Back
and if there is a way to produce the same effect as the bottom one (low latency?) with XInput, as calling Joy7 doesn't work with my controller when not in focus. By testing, I learned that the resources for both are negligible. I don't know if you saw my edit, but UCR.ahk (viewtopic.php?t=12249) works well and I was also wondering how that works if you know.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: XInput doesn't see controller inputs when not in focus

Post by swagfag » 29 Jan 2022, 12:53

it uses xinput too

Post Reply

Return to “Ask for Help (v1)”