Page 1 of 1

Defining joystick hotkeys is slowing down my script.

Posted: 15 Oct 2021, 07:03
by chinagreenelvis
I'm doing a simple loop with a messagebox from random files in a folder. The loop moves at normal (fast) speed, but the moment I add the following:

Code: Select all

~1Joy1::

Return
It moves WAY slower. I don't understand what's happening or how to mitigate it.

Re: Defining joystick hotkeys is slowing down my script.

Posted: 25 Mar 2022, 00:29
by chinagreenelvis
I asked this last year and am still having the same issue. Bump.

Re: Defining joystick hotkeys is slowing down my script.

Posted: 25 Mar 2022, 00:33
by chinagreenelvis
Okay, so apparently the problem here is the script is slowed down if the joystick is not actually connected. I'm noticing the same problem when defining a hotkey for a second controller; if the second controller is not connected, the hotkeys for the first controller have a MASSIVE delay.

Surely AHK doesn't actually expect to have every controller always connected, so there must be a workaround for this?

Re: Defining joystick hotkeys is slowing down my script.  Topic is solved

Posted: 25 Mar 2022, 01:18
by boiler
You could poll the joystick with GetKeyState, such as a lever that will only have a value within a certain range when it is connected. Then only after finding a joystick is connected, you could create the hotkey(s) using the Hotkey command.

Re: Defining joystick hotkeys is slowing down my script.

Posted: 25 Mar 2022, 13:09
by chinagreenelvis
Thanks, that is the correct answer. I found it in an older thread about high CPU usage when defining hotkeys for disconnected controllers.

My particular solution was the same as in that thread, to poll the controller at the start of the script and then map hotkeys to subroutines.

Code: Select all

If GetKeyState("1JoyName")
{
 Hotkey, 1Joy8, 1J8
}

1J8:
	;Do a thing
Return


Re: Defining joystick hotkeys is slowing down my script.

Posted: 25 Mar 2022, 14:13
by doubledave22
chinagreenelvis wrote:
25 Mar 2022, 13:09
Thanks, that is the correct answer. I found it in an older thread about high CPU usage when defining hotkeys for disconnected controllers.

My particular solution was the same as in that thread, to poll the controller at the start of the script and then map hotkeys to subroutines.
Yeah this can work. It might have been my thread you found. My ultimate solution was to switch to evilc's joystickwrapper viewtopic.php?t=28889 (I'm using xinput)

It's a bit of setup but works better for my use and avoids the windows bug with polling controllers that have been unplugged