xbox 360 controller timed auto-repeat?

Ask gaming related questions (AHK v1.1 and older)
Longwing
Posts: 5
Joined: 24 Jun 2017, 19:02

xbox 360 controller timed auto-repeat?

24 Jun 2017, 19:13

So I'm trying to solve a very specific problem with the game Hyper Light Drifter. It's an excellent game, but it has an extremely frustrating dash mechanic that requires ridiculously precise timing to function.

What I'd like to do is set up an AHK script that modifies the behavior of a standard Xbox 360 controller's A button. When pressed and released, it should function normally. When held down, it should repeat at 150 milliseconds between presses until released.

Is this possible? I've been experimenting with a keyboard version of this, which works perfectly in notepad, but doesn't register in the game. Frustratingly, the game will only accept either keyboard or controller input at any given moment, not both. I'd prefer to play with a controller, though I could switch to playing with keyboard/mouse if I can get this script to register in-game. I'd appreciate any suggestions.

Here's what I have for the keyboard, though this doesn't seem to register in-game:

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#UseHook
#InstallMouseHook
#InstallKeybdHook
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

$Space::
 While GetKeyState("Space","p"){
  Send {space}
  Sleep 150
 }
return
Longwing
Posts: 5
Joined: 24 Jun 2017, 19:02

Re: xbox 360 controller timed auto-repeat?

25 Jun 2017, 16:57

After some experimentation, I've made progress but I'm still working my way through issues. First, here's the current version of the script:

Code: Select all

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#UseHook
#InstallMouseHook
#InstallKeybdHook
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetKeyDelay, 140

$Space::
While GetKeyState("Space","p"){
     Send, {space down}
     Sleep .5
     Send, {space up}
     return
}
This variation gets the timing right and allows a chain auto-dash to continue indefinitely. Curiously, dropping the Sleep delay below 1 causes AHK to throw an anti-infinite-loop warning as soon as the key is released. This is worrysome. I know the warning can be disabled (this may be needed to make the script viable), but I'm leery of telling an infinite-loop blocker that it needs to shut up.

I have yet to swap this over to running controller commands. That will likely be my next step but requires learning the ins and outs of AHK's interactions with controllers.
Longwing
Posts: 5
Joined: 24 Jun 2017, 19:02

Re: xbox 360 controller timed auto-repeat?

26 Jun 2017, 20:49

I tried the Joystick script (https://autohotkey.com/docs/scripts/JoystickTest.htm) to detect button presses, but it doesn't seem to find the button presses from an Xbox 360 wireless controller. Nothing registered in the script. I suppose I'll have to find another way to identify the A button.
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: xbox 360 controller timed auto-repeat?

27 Jun 2017, 09:44

Moved to gaming at request of OP
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Longwing
Posts: 5
Joined: 24 Jun 2017, 19:02

Re: xbox 360 controller timed auto-repeat?

28 Jun 2017, 14:20

That's a pity. Well, I CAN play the game with a keyboard and mouse, even though it's "Designed" for a controller. Any thoughts on my infinite loop problem? I was reading somewhere in the docs that you can just instruct AHK to shut up about it, but that seems like a terrible idea if there's a better alternative available.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: xbox 360 controller timed auto-repeat?

28 Jun 2017, 14:28

Assuming your joypad is stick ID #1 and the keyboard equivalent of the A button is Space:

Code: Select all

SetKeyDelay, 0, 50	; Hold all keys for at least 50ms - many games need this
1Joy1::	; 1st number is joystick ID, 2nd is button number
	while (GetKeyState(A_ThisHotkey)){	; while the button is held...
		Send {Space}
		Sleep 100	; Wait for 100ms - as the key is held for 50ms, then space will be sent once every 150ms.
	}
	return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: xbox 360 controller timed auto-repeat?

28 Jun 2017, 14:33

Oh, just noticed this requirement:
When pressed and released, it should function normally. When held down, it should repeat at 150 ms
This is not as simple as it sounds.
When the button goes down, AHK cannot look in the future to know if you will keep holding the button.
So @ 150ms, what does it do?

The way this is generally solved:
When the button is pressed, do nothing. If the button is still held after <timeout>, then assume hold.
If the button is released before <timeout>, then that was a press - so the output gets pressed *at this point* for a tap.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 57 guests