simple script only works when AHK is open

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
altokers
Posts: 6
Joined: 24 Nov 2022, 08:51

simple script only works when AHK is open

Post by altokers » 24 Nov 2022, 08:55

So i just want to use this script to make my xbone controller open a .bat file, the problem is it only works when i have the ahk opened and focused on.

can anyone help?

Code: Select all

1Joy12::Run, "J:\Program Files\Kodi\focusonkodi.bat"

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: simple script only works when AHK is open

Post by mikeyww » 24 Nov 2022, 09:52

Welcome to this AutoHotkey forum!

Uncompiled AutoHotkey scripts run in the background as tray-resident programs with AutoHotkey.exe (generally). The script must be running for it to work. Whether the script's own interface (window) is visible makes no difference.

It is possible for another program to "block" or ignore a script when that program's window is active. This can sometimes be overcome via UI Access or running as admin, both explained in the documentation. Trying UI Access is recommended first.

altokers
Posts: 6
Joined: 24 Nov 2022, 08:51

Re: simple script only works when AHK is open

Post by altokers » 24 Nov 2022, 12:35

mikeyww wrote:
24 Nov 2022, 09:52
Welcome to this AutoHotkey forum!

Uncompiled AutoHotkey scripts run in the background as tray-resident programs with AutoHotkey.exe (generally). The script must be running for it to work. Whether the script's own interface (window) is visible makes no difference.

It is possible for another program to "block" or ignore a script when that program's window is active. This can sometimes be overcome via UI Access or running as admin, both explained in the documentation. Trying UI Access is recommended first.
Yeah i don't think it should but that's how it's working for me..

i tried running it as admin and compiling it, it was no different. The only thing that allows it to start the .bat file is being in focus.

how do i give it ui access? It's not obvious from the doc to me.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: simple script only works when AHK is open

Post by mikeyww » 24 Nov 2022, 13:55

Things to try:
1. Test of hotkey => See if a different hotkey works.
2. Test of command => See if a message box works.

Code: Select all

1Joy12::MsgBox, Test
3. Have a look at https://www.autohotkey.com/docs/KeyList.htm#Joystick (general information)
4. Test of access => https://www.autohotkey.com/docs/Program.htm#Installer_uiAccess

Test only that code or script-- no other code in the script, and no other scripts running.

What do you mean by
ahk opened
:?:

Can you provide a screenshot?

altokers
Posts: 6
Joined: 24 Nov 2022, 08:51

Re: simple script only works when AHK is open

Post by altokers » 24 Nov 2022, 14:54

mikeyww wrote:
24 Nov 2022, 13:55
Things to try:
1. Test of hotkey => See if a different hotkey works.
2. Test of command => See if a message box works.

Code: Select all

1Joy12::MsgBox, Test
3. Have a look at https://www.autohotkey.com/docs/KeyList.htm#Joystick (general information)
4. Test of access => https://www.autohotkey.com/docs/Program.htm#Installer_uiAccess

Test only that code or script-- no other code in the script, and no other scripts running.

What do you mean by
ahk opened
:?:

Can you provide a screenshot?
I think i figured it out, it seems to be a problem with using joystick buttons.

when i change it to a keyboard combo it works fine regardless of focus.

is there some special way you need to input joystick buttons to ignore window focus?

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: simple script only works when AHK is open

Post by mikeyww » 24 Nov 2022, 18:02

I do not understand the question, but I'm not the best person to answer questions about joystick. Others may know, though you may also want to clarify your question.

altokers
Posts: 6
Joined: 24 Nov 2022, 08:51

Re: simple script only works when AHK is open

Post by altokers » 24 Nov 2022, 21:58

mikeyww wrote:
24 Nov 2022, 18:02
I do not understand the question, but I'm not the best person to answer questions about joystick. Others may know, though you may also want to clarify your question.
I want to press a button on my controller to have it launch a .bat file, but it seems that when using joystick commands ahk requires the ahk script to be open and the window in focus (by right clicking on ahk icon in the tray and opening the running script)

so basically i just need to know if there is some other special command to force joystick buttons to work when the window is not in focus.

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

Re: simple script only works when AHK is open

Post by boiler » 24 Nov 2022, 22:07

altokers wrote: it seems that when using joystick commands ahk requires the ahk script to be open and the window in focus (by right clicking on ahk icon in the tray and opening the running script)
This is not the case. You must have some other issue going on. Did you run mikeyww’s script to display the MsgBox? Did that script work?

altokers
Posts: 6
Joined: 24 Nov 2022, 08:51

Re: simple script only works when AHK is open

Post by altokers » 25 Nov 2022, 22:07

boiler wrote:
24 Nov 2022, 22:07
altokers wrote: it seems that when using joystick commands ahk requires the ahk script to be open and the window in focus (by right clicking on ahk icon in the tray and opening the running script)
This is not the case. You must have some other issue going on. Did you run mikeyww’s script to display the MsgBox? Did that script work?
it does not work when using the joystick commands.

tried it with a keyboard one and it worked then.

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

Re: simple script only works when AHK is open

Post by boiler » 25 Nov 2022, 23:37

Run the Joystick Test Script and see if that works. If so, what does it show for your joystick number?

Also, what version of AHK are you using? You might want to upgrade to the latest (1.1.35) because there were joystick problems with some older versions.

altokers
Posts: 6
Joined: 24 Nov 2022, 08:51

Re: simple script only works when AHK is open

Post by altokers » 26 Nov 2022, 17:46

boiler wrote:
25 Nov 2022, 23:37
Run the Joystick Test Script and see if that works. If so, what does it show for your joystick number?

Also, what version of AHK are you using? You might want to upgrade to the latest (1.1.35) because there were joystick problems with some older versions.
it is the latest one, just installed it a few days ago.

and yeah the joystick test script detects it (that's how i got the number in the first place) but it has the same problem, only works when the script is in focus.

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

Re: simple script only works when AHK is open

Post by boiler » 26 Nov 2022, 20:58

The only thing I can think of is that you perhaps have some other controller software installed that is interfering with AHK if other windows are active.

Post Reply

Return to “Ask for Help (v1)”