Page 1 of 1

Color detection Sending a key press

Posted: 19 May 2022, 03:35
by akramfex
hello, I'm trying to make a script that allows me to trigger a key (hold press) when I'm hovering on a given color, this script will be triggered as long impressing a key (hold press), i tried to loop the color detection, the script is not working at all !

Code: Select all

#IfWinActive, ahk_exe Photoshop.exe
#InstallKeybdHook

Loop {
MouseGetPos, MouseX, MouseY
PixelGetColor, color, %MouseX%, %MouseY%
}

if color = ff0000 ; Color here
#if getkeystate("Lbutton","p") ; as long im pressing Lbutton this script will run and send the b key
Send, {b}
return

#if

Re: Color detection Sending a key press

Posted: 19 May 2022, 04:36
by Rohwedder
Hallo,
try;

Code: Select all

#InstallKeybdHook
#IfWinActive, ahk_exe Photoshop.exe
~LButton::SetTimer, Color, 100
~LButton Up::SetTimer, Color, Off
; as long im pressing Lbutton this script will run and send the b key
Color:
MouseGetPos, MouseX, MouseY
PixelGetColor, color, MouseX, MouseY
if color = 0xff0000 ; Color here
	Send, {LButton Up}{b}{LButton Down}
return
#if

Re: Color detection Sending a key press

Posted: 19 May 2022, 06:48
by akramfex
Hi, thank you for the response, I tried the script and it seems not doing anything, just to show the color code, maybe I'm writing the theme wrong in the script ?

Re: Color detection Sending a key press

Posted: 19 May 2022, 07:47
by Rohwedder
Yes!
Try:

Code: Select all

#InstallKeybdHook
#IfWinActive, ahk_exe Photoshop.exe
~LButton::SetTimer, Color, 100
~LButton Up::SetTimer, Color, Off
; as long im pressing Lbutton this script will run and send the b key
Color:
MouseGetPos, MouseX, MouseY
PixelGetColor, color, MouseX, MouseY
; ToolTip,% color
if color = 0x1C00FC ; Color here
{
	; SoundBeep, 4000, 20
	Send, {LButton Up}{b}{LButton Down}
}
return
#if