make script work in background Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
oresa
Posts: 4
Joined: 21 Aug 2018, 06:17

make script work in background

21 Aug 2018, 06:27

Hello everyone I have created a really small script for a game that would click things for me but I have been struggling to make it work when the game window isnt active.
Here is my script:

Code: Select all

r::
   loop,
 {
   click 1183, 914 down
   sleep, 7000
   click 1183, 914 up
   sleep, 1000
   click 315, 909 down
   sleep, 1000
   click 315, 909 up
   sleep, 1000
 }
t::exitapp
Any and all help is appreciated.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: make script work in background  Topic is solved

21 Aug 2018, 07:08

Hi,
I believe you must checkout these commands:
#if not WinActive
https://autohotkey.com/docs/commands/WinActive.htm
ControlClick
https://autohotkey.com/docs/commands/ControlClick.htm

You can then split your script in part 1: if winactive and part2: if not winactive.
This means it will always work - doesn't matter if the application is in foreground or background.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
oresa
Posts: 4
Joined: 21 Aug 2018, 06:17

Re: make script work in background

21 Aug 2018, 09:28

Thank you very much I will try to make it work using those commands.
oresa
Posts: 4
Joined: 21 Aug 2018, 06:17

Re: make script work in background

21 Aug 2018, 09:46

Edit: Everything works flawlessly with ControlClick !!!! :dance: :dance: :dance:
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: make script work in background

21 Aug 2018, 11:42

it's been barely 15 min. are u sure uve had enough time to read through both articles and grasp the concepts involved? have u tried anything already?

ControlSend with coordinates works like this:

Code: Select all

ControlSend, X100 Y100, % "ahk_id" ur_window_HWND, , LEFT, 1, D ; generates a LMB-down event
ControlSend, X100 Y100, % "ahk_id" ur_window_HWND, , LEFT, 1, U ; generates a LMB-up event
to figure out what the window HWND is, u can use WinExist() or WinActive():

Code: Select all

hwnd := WinActive("A") ; hwnd of currently focused window
hwnd := WinActive("ahk_exe name_of_exe.exe") ; use exe name, ex. 'notepad.exe'
hwnd := WinActive("Skype") ; use window title, see also SetTitleMatchMode 
oresa
Posts: 4
Joined: 21 Aug 2018, 06:17

Re: make script work in background

21 Aug 2018, 11:51

I have tried my little crappy concept with IfWin(Not)Active and CotrolClick and it works even better than expected. (I did not read the whole articles just enough to get what I needed) Thanks for the advice anyway.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb and 325 guests