Running a script on a specific window even while alt tabbed.
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Running a script on a specific window even while alt tabbed.
Hey guys. So I have this script that runs on a game to afk farm. I noticed that the script still runs even when the game window is in the background, hence messing things up on my desktop.
Is there a way to run the script only on the game window? Even while its on the background or alt-tabbed? I want to do other tasks on my PC while doing it so any help will be much appreciated.
Greetings from the Philippines.
Is there a way to run the script only on the game window? Even while its on the background or alt-tabbed? I want to do other tasks on my PC while doing it so any help will be much appreciated.
Greetings from the Philippines.
Re: Running a script on a specific window even while alt tabbed.
You can change Send to ControlSend. It does not respond to all windows. Post your script for feedback.
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
Here's the code I'm using.
Code: Select all
#MaxThreadsperHotkey 2
NumpadAdd::ExitApp
~F1::
Find := !Find
While Find
{
PixelSearch, Px, Py, 662, 662, 60, 60, 0x618EB5, 1, Fast
If ErrorLevel
{
Sleep, 400
MouseMove 405, 325
Send, {F1}
Sleep, 150
MouseClick, Left
Sleep, 400
Send, {F3}
}
Else
{
Sleep, 2000
Send, @warp prontera 162 170{Enter}
Sleep, 2000
MouseMove 495, 290
Sleep, 2000
MouseClick, Left
Sleep, 2000
Send, {Enter}
Sleep, 2000
}
}
Return
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
Example:
In some cases, tips for games can also be helpful.
https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
Code: Select all
ControlSend,, {F1}, Mob Ragnarok
https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
Should I just place this at the top of my code?mikeyww wrote: ↑23 Apr 2021, 19:09Example:
In some cases, tips for games can also be helpful.Code: Select all
ControlSend,, {F1}, Mob Ragnarok
https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
Code: Select all
NumPadAdd::ExitApp
#MaxThreadsperHotkey 2
~F1::
Previouskey:= !PreviousKey
Loop
{
If PreviousKey
{
Sleep, 200
MouseMove 405, 325
Send, {F1}
Sleep, 150
MouseClick, Left
Sleep, 200
Send, {F3}
}
Else
Break
}
Return
Re: Running a script on a specific window even while alt tabbed.
It's an example instead of Send {F1}. It shows you how you can use ControlSend as a command, to send to an inactive window. Instead of trying your entire script, try just one ControlSend command, to see if it works.
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
Ok, it seem to be working fine but the click command does not register.
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
This is my revised code:
All commands seems to be working fine aside from the ControlClick command. What am I doing wrong?
Code: Select all
#MaxThreadsperHotkey 2
NumPadAdd::ExitApp
~F1::
Previouskey:= !PreviousKey
Loop
{
If PreviousKey
{
ControlSend,, {F1}, Mob Ragnarok
Sleep, 200
Send, {F1}
Sleep, 150
ControlClick, x405 y325, Mob Ragnarok,, L
Sleep, 200
Send, {F3}
}
Else
Break
}
Return
Re: Running a script on a specific window even while alt tabbed.
I do not have a way to test it. You can double-check your coordinates by issuing a MouseMove to the same coordinates while the window is active.
You could also change your hotkey in your testing. When you send F1, you may unexpectedly trigger a loop that also exits the routine (intermittently). To prevent the loop, include $ as a hotkey modifier prefix.
Explained: Hotkey modifier symbols
You could also change your hotkey in your testing. When you send F1, you may unexpectedly trigger a loop that also exits the routine (intermittently). To prevent the loop, include $ as a hotkey modifier prefix.
Explained: Hotkey modifier symbols
-
- Posts: 16
- Joined: 21 Apr 2021, 15:21
Re: Running a script on a specific window even while alt tabbed.
I double-checked the coordinates using MouseMove but it still doesn't register the command, It clicks where my mouse pointer is located but not on the specified coordinates. Same goes when I change the modifier prefix. I've read somewhere that says ControlClick doesn't always work on all games but I can't confirm it. That being said, is there a possible alternative command for ControlClick?
Re: Running a script on a specific window even while alt tabbed.
Two ideas:
First, since you are indicating that MouseMove works and Click works, you could issue them in sequence, instead of ControlClick (or just move the mouse first, and then issue the click or ControlClick).
Second, the tips for games are sometimes helpful. In some cases, admin mode is needed, or holding the keys or buttons for longer than usual.
https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/
First, since you are indicating that MouseMove works and Click works, you could issue them in sequence, instead of ControlClick (or just move the mouse first, and then issue the click or ControlClick).
Second, the tips for games are sometimes helpful. In some cases, admin mode is needed, or holding the keys or buttons for longer than usual.
https://autohotkey.com/board/topic/111737-how-to-make-ahk-work-in-most-games-the-basics/