Press Keystroke if Color on Screen is detected Topic is solved
Press Keystroke if Color on Screen is detected
Hello. I did find some v1 Examples but they didn't work for me, so i thought i'd ask for a v2 Code.
I need a script that loops and everytime the color 0x43948D is visible in the game on Monitor 1 press the keystroke E.
Is there a way to do this?
I need a script that loops and everytime the color 0x43948D is visible in the game on Monitor 1 press the keystroke E.
Is there a way to do this?
Re: Press Keystroke if Color on Screen is detected
Welcome to this AutoHotkey forum!
Code: Select all
#Requires AutoHotkey v2.0
game := 'ahk_exe notepad.exe'
rgb := 0x43948D
WinGetClientPos &x1, &y1, &width, &height, game
CoordMode 'Pixel'
WinActivate game
SetKeyDelay , PRESSDURATION := 25
Loop {
Sleep 30
If PixelSearch(&x, &y, x1, y1, x1 + width - 1, y1 + height - 1, rgb)
SendEvent 'e'
}
Re: Press Keystroke if Color on Screen is detected
Hey, thank you very much for the Hotkey. Is there any way to extend the code so that it counts the amount of times it detected the color and presses an additional hotkey (e) certain milliseconds after for example the fifth color detection?
So:
Detected Color -> E
Detected Color -> E
Detected Color -> E
Detected Color -> E
Detected Color -> E
Detected the color 5 times -> wait some ms -> press e, reset count
Re: Press Keystroke if Color on Screen is detected Topic is solved
Code: Select all
#Requires AutoHotkey v2.0
game := 'ahk_exe notepad.exe'
rgb := 0x43948D
WinGetClientPos &x1, &y1, &width, &height, game
CoordMode 'Pixel'
WinActivate game
SetKeyDelay , PRESSDURATION := 25
n := 0
x2 := x1 + width - 1
y2 := y1 + height - 1
Loop {
Sleep 30
If PixelSearch(&x, &y, x1, y1, x2, y2, rgb) {
SendEvent 'e'
If ++n = 5 {
Sleep 100
SendEvent 'e'
n := 0
}
}
}
Re: Press Keystroke if Color on Screen is detected
Hey @mikeyww
this works perfect, thank you.
this works perfect, thank you.
Re: Press Keystroke if Color on Screen is detected
Is there any way to extend this a little so that it runs if i press a specific button and when i press the button again it stops and resumes if i press it again?mikeyww wrote: ↑26 Aug 2023, 01:20Code: Select all
#Requires AutoHotkey v2.0 game := 'ahk_exe notepad.exe' rgb := 0x43948D WinGetClientPos &x1, &y1, &width, &height, game CoordMode 'Pixel' WinActivate game SetKeyDelay , PRESSDURATION := 25 n := 0 x2 := x1 + width - 1 y2 := y1 + height - 1 Loop { Sleep 30 If PixelSearch(&x, &y, x1, y1, x2, y2, rgb) { SendEvent 'e' If ++n = 5 { Sleep 100 SendEvent 'e' n := 0 } } }
Re: Press Keystroke if Color on Screen is detected
An alternative is below.
Code: Select all
#Requires AutoHotkey v2.0
#MaxThreadsPerHotkey 2
SoundBeep 1500
F3:: {
Static on := False
on := !on
While on {
Send 'e'
Sleep 200
}
Reload
}