Click when something changes in the middle of the screen

Ask gaming related questions (AHK v1.1 and older)
qwertyhim513
Posts: 5
Joined: 03 Nov 2021, 19:33

Click when something changes in the middle of the screen

Post by qwertyhim513 » 23 Jan 2022, 18:23

Hello,

I'm trying to have a script that automatically clicks when something changes in the middle of the screen. The idea is that a friend has a reaction mini-game where a small square appears in the middle and you must click the mouse once as soon as possible when it appears, but random things will blink into existence outside the center(which shouldn't affect your clicking). Does anyone have tips on how to do this?

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

Re: Click when something changes in the middle of the screen

Post by mikeyww » 23 Jan 2022, 19:08

A demonstration is below.

Code: Select all

color := "0000FF", cx := A_ScreenWidth / 2, cy := A_ScreenHeight / 2
width := 40, x := cx - width / 2, y := cy - width / 2
Gui, -Caption +AlwaysOnTop -DPIScale
Gui, Margin, 0, 0
Gui, Add, Progress, w%width% h%width% c%color%, 100
Gui, Found:New,, Found
Gui, Font, s20 w600
Gui, Add, Text, w200 Center, Nailed it!
Random, rand, 1000, 3000
SetTimer, Show, -%rand%         ; Display a small square at a random time
SetTimer, Find, 100             ; Search for the color
SoundBeep, 1500
ToolTip, Please wait....
Return

Show:
Gui, Show, x%x% y%y%            ; Show a small square in the center of the screen
Return

Find:
CoordMode, Pixel
CoordMode, Mouse
PixelGetColor, rgb, cx, cy, RGB ; Get the color
If (rgb != "0x" color)
 Return
SetTimer,, Off                  ; Color was found
MouseClick,, cx, cy             ; Click on the spot
SoundBeep, 1000
ToolTip
Gui, Found:Show, x200 y400      ; Display an information message
Return

qwertyhim513
Posts: 5
Joined: 03 Nov 2021, 19:33

Re: Click when something changes in the middle of the screen

Post by qwertyhim513 » 23 Jan 2022, 22:03

Thanks for the quick response. So the game my friend and I are testing doesn't actually want you to move the mouse. More like immediately press the left click whenever the center of the screen changes. For testing reasons, would it be possible to have it so while we have a key(lets say "t") have the script run, otherwise do nothing if nothing is pressed?

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

Re: Click when something changes in the middle of the screen

Post by mikeyww » 24 Jan 2022, 07:02

Sure.

Code: Select all

color := "0000FF", cx := A_ScreenWidth / 2, cy := A_ScreenHeight / 2
width := 40, x := cx - width / 2, y := cy - width / 2
Gui, -Caption +AlwaysOnTop -DPIScale
Gui, Margin, 0, 0
Gui, Add, Progress, w%width% h%width% c%color%, 100
Gui, Show, x%x% y%y%                  ; Show a small square in the center of the screen
Gui, Found:New, +AlwaysOnTop, Found
Gui, Font, s20 w600
Gui, Add, Text, w200 Center, Nailed it!
SoundBeep, 1500

t::                                   ; T = Repeatedly search for the color
ToolTip, Please wait....
SetTimer, Find, 150
SoundBeep, 1900
Return

Find:
CoordMode, Pixel
CoordMode, Mouse
PixelGetColor, rgb, cx, cy, RGB ; Get the color
If (rgb != "0x" color)
 Return
SetTimer,, Off                        ; Color was found
; MouseClick,, cx, cy                 ; Click on the spot
Click
SoundBeep, 1000
ToolTip
Gui, Found:Show, x200 y400 NoActivate ; Display an informational message
Return

Post Reply

Return to “Gaming Help (v1)”