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?
Click when something changes in the middle of the screen
-
- Posts: 5
- Joined: 03 Nov 2021, 19:33
Re: Click when something changes in the middle of the screen
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
-
- Posts: 5
- Joined: 03 Nov 2021, 19:33
Re: Click when something changes in the middle of the screen
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?
Re: Click when something changes in the middle of the screen
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