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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Defining joystick hotkeys is slowing down my script.

Post by chinagreenelvis » 15 Oct 2021, 07:03

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.

chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Re: Defining joystick hotkeys is slowing down my script.

Post by chinagreenelvis » 25 Mar 2022, 00:29

I asked this last year and am still having the same issue. Bump.

chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Re: Defining joystick hotkeys is slowing down my script.

Post by chinagreenelvis » 25 Mar 2022, 00:33

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?

User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 25 Mar 2022, 01:18

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.

chinagreenelvis
Posts: 133
Joined: 19 Oct 2015, 16:21

Re: Defining joystick hotkeys is slowing down my script.

Post by chinagreenelvis » 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.

Code: Select all

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

1J8:
	;Do a thing
Return


doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Defining joystick hotkeys is slowing down my script.

Post by doubledave22 » 25 Mar 2022, 14:13

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

Post Reply

Return to “Ask for Help (v1)”