Controller Input Only Works While AHK Window is Open

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Controller Input Only Works While AHK Window is Open

Post by Breadn » 26 May 2023, 19:42

Title. Controller input is only detected while the main AHK window is open (by double clicking on the icon in the tray). As soon as I click off or minimize it, controller input is no longer detected.

Code: Select all

1joy1::
MsgBox Test


Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 27 May 2023, 06:56

boiler wrote:
26 May 2023, 23:18
See this post.
Where do I find xinput1.dll ?

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 27 May 2023, 07:04

Like he said, you probably already have it and don't have to do anything. Did you try it and find that it couldn't find it? It's not xinput1.dll, by the way. He said xinput1_*.dll. On my system it's XInput1_4.dll

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 27 May 2023, 08:16

boiler wrote:
27 May 2023, 07:04
Like he said, you probably already have it and don't have to do anything. Did you try it and find that it couldn't find it? It's not xinput1.dll, by the way. He said xinput1_*.dll. On my system it's XInput1_4.dll
Couldn't find it, at least I assume. Got this error when running the code.

Error at line 1.
Line Text: #Include <XInput>
Error: Function library not found.

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 27 May 2023, 08:21

That’s not the dll file it’s not finding. That’s the ahk file itself. Did you download lexikos’ library? Where did you put it? To use that style of #Include syntax, it needs to be in a standard library location. Otherwise, use the “normal” include syntax. See the documentation for details. Make sure you use the v1 version since you are apparently using AHK v1.

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 27 May 2023, 09:13

boiler wrote:
27 May 2023, 08:21
That’s not the dll file it’s not finding. That’s the ahk file itself. Did you download lexikos’ library? Where did you put it? To use that style of #Include syntax, it needs to be in a standard library location. Otherwise, use the “normal” include syntax. See the documentation for details. Make sure you use the v1 version since you are apparently using AHK v1.
What documentation? The forum post for the API contains very little. If you're referring to the first batch of code from the forum post, I have no clue how to install it.

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 27 May 2023, 10:24

No, I mean the AHK documentation on #Include. It seemed like you may not be aware that’s the file to be included has to be located in a specific place if you’re going to use the < > syntax, so that’s why I suggested reading that part of the documentation.

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 27 May 2023, 13:23

boiler wrote:
27 May 2023, 10:24
No, I mean the AHK documentation on #Include. It seemed like you may not be aware that’s the file to be included has to be located in a specific place if you’re going to use the < > syntax, so that’s why I suggested reading that part of the documentation.
Alright, I got the library and script working, thanks for linking the documentation. But is there more documentation somewhere on the library? Like how to figure out what each controller button is named?

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 27 May 2023, 14:03

Check out the Controller Test Script from the documentation’s Script Showcase.

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 27 May 2023, 15:14

boiler wrote:
27 May 2023, 14:03
Check out the Controller Test Script from the documentation’s Script Showcase.
Then I run into the same issue I had before. It only works with the main AHK window open.

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 27 May 2023, 16:01

Breadn wrote: Then I run into the same issue I had before. It only works with the main AHK window open.
So? Why is that a problem for finding out what each controller button is named?

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 27 May 2023, 18:02

boiler wrote:
27 May 2023, 16:01
Breadn wrote: Then I run into the same issue I had before. It only works with the main AHK window open.
So? Why is that a problem for finding out what each controller button is named?
Because I'm back to square one. I figure out the button, I try to use it as a hotkey, and it doesn't work when out of focus.

Code: Select all

1joy1::
msgBox Test

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 27 May 2023, 23:47

Breadn wrote:
27 May 2023, 18:02
Because I'm back to square one. I figure out the button, I try to use it as a hotkey, and it doesn't work when out of focus.
You have to use the library. I was just telling you to use the other script to see what the various buttons are. To use the library, follow the examples at that link.

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 28 May 2023, 09:48

boiler wrote:
27 May 2023, 23:47
Breadn wrote:
27 May 2023, 18:02
Because I'm back to square one. I figure out the button, I try to use it as a hotkey, and it doesn't work when out of focus.
You have to use the library. I was just telling you to use the other script to see what the various buttons are. To use the library, follow the examples at that link.
I don't understand how to use it, the notes in the code are vague and it's out of my reach as a beginner.

How can I use one of my controller buttons as a hotkey? That's all I want to do.

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 28 May 2023, 10:02

I’ve never used it, but looking at the user notes in the code, it apparently doesn’t support making hotkeys out of the buttons. You would have to have your script continuously check the state of the buttons and act when the state of the button of interest indicates it has been pressed, as shown in the example.

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 28 May 2023, 13:50

boiler wrote:
28 May 2023, 10:02
I’ve never used it, but looking at the user notes in the code, it apparently doesn’t support making hotkeys out of the buttons. You would have to have your script continuously check the state of the buttons and act when the state of the button of interest indicates it has been pressed, as shown in the example.
I'm looking at the example code and notes in the library and I don't understand it.

Code: Select all

XInput_Init()
Loop {
    Loop, 4 {
        if State := XInput_GetState(A_Index-1) {
            LT := State.bLeftTrigger
            RT := State.bRightTrigger
            XInput_SetState(A_Index-1, LT*257, RT*257)
        }
    }
    Sleep, 100
}
It's getting the state of triggers, which are referred to as State.bLeftTrigger. But then, what are the face buttons referred to as? Surely not just "1" or "4" as the button test seems to suggest. And once you get the state of it, how do you go on to perform an action? I just don't get any of it.

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 28 May 2023, 14:20

For the buttons, you need to use State.wButtons, and you can tell which button (or multiple buttons) are pressed by its value. It is one number that contains the state of all the buttons at once, and you need to do bitwise math on it to see if a specific button is pressed, as outlined in the comments:

Code: Select all

    ; Constants for gamepad buttons
    XINPUT_GAMEPAD_DPAD_UP          := 0x0001
    XINPUT_GAMEPAD_DPAD_DOWN        := 0x0002
    XINPUT_GAMEPAD_DPAD_LEFT        := 0x0004
    XINPUT_GAMEPAD_DPAD_RIGHT       := 0x0008
    XINPUT_GAMEPAD_START            := 0x0010
    XINPUT_GAMEPAD_BACK             := 0x0020
    XINPUT_GAMEPAD_LEFT_THUMB       := 0x0040
    XINPUT_GAMEPAD_RIGHT_THUMB      := 0x0080
    XINPUT_GAMEPAD_LEFT_SHOULDER    := 0x0100
    XINPUT_GAMEPAD_RIGHT_SHOULDER   := 0x0200
    XINPUT_GAMEPAD_GUIDE            := 0x0400
    XINPUT_GAMEPAD_A                := 0x1000
    XINPUT_GAMEPAD_B                := 0x2000
    XINPUT_GAMEPAD_X                := 0x4000
    XINPUT_GAMEPAD_Y                := 0x8000

It sounds like it is probably too complex for you, and I’m not sure how to help you other than to make a wrapper function for his wrapper function to simplify it, which I don’t have time to do right now.

Breadn
Posts: 13
Joined: 26 May 2023, 13:26

Re: Controller Input Only Works While AHK Window is Open

Post by Breadn » 28 May 2023, 14:56

boiler wrote:
28 May 2023, 14:20
For the buttons, you need to use State.wButtons, and you can tell which button (or multiple buttons) are pressed by its value. It is one number that contains the state of all the buttons at once, and you need to do bitwise math on it to see if a specific button is pressed, as outlined in the comments:

Code: Select all

    ; Constants for gamepad buttons
    XINPUT_GAMEPAD_DPAD_UP          := 0x0001
    XINPUT_GAMEPAD_DPAD_DOWN        := 0x0002
    XINPUT_GAMEPAD_DPAD_LEFT        := 0x0004
    XINPUT_GAMEPAD_DPAD_RIGHT       := 0x0008
    XINPUT_GAMEPAD_START            := 0x0010
    XINPUT_GAMEPAD_BACK             := 0x0020
    XINPUT_GAMEPAD_LEFT_THUMB       := 0x0040
    XINPUT_GAMEPAD_RIGHT_THUMB      := 0x0080
    XINPUT_GAMEPAD_LEFT_SHOULDER    := 0x0100
    XINPUT_GAMEPAD_RIGHT_SHOULDER   := 0x0200
    XINPUT_GAMEPAD_GUIDE            := 0x0400
    XINPUT_GAMEPAD_A                := 0x1000
    XINPUT_GAMEPAD_B                := 0x2000
    XINPUT_GAMEPAD_X                := 0x4000
    XINPUT_GAMEPAD_Y                := 0x8000

It sounds like it is probably too complex for you, and I’m not sure how to help you other than to make a wrapper function for his wrapper function to simplify it, which I don’t have time to do right now.
I mean, all I want to do is have the following performed when I hit the left trigger.

Code: Select all

Click, 1794, 685, Down
sleep 100
Click, 1794, 685, Up

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

Re: Controller Input Only Works While AHK Window is Open

Post by boiler » 28 May 2023, 15:12

Code: Select all

#Include <XInput>

XInput_Init()
Loop {
    Loop, 4 {
        if State := XInput_GetState(A_Index-1) {
            if (State.bLeftTrigger > 0) {
				Click, 1794, 685, Down
				Sleep, 100
				Click, 1794, 685, Up
			}
        }
    }
    Sleep, 100
}
return

Post Reply

Return to “Ask for Help (v1)”