Color detection Sending a key press

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
akramfex
Posts: 5
Joined: 24 Dec 2021, 11:51

Color detection Sending a key press

Post by akramfex » 19 May 2022, 03:35

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

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Color detection Sending a key press

Post by Rohwedder » 19 May 2022, 04:36

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

akramfex
Posts: 5
Joined: 24 Dec 2021, 11:51

Re: Color detection Sending a key press

Post by akramfex » 19 May 2022, 06:48

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 ?
Attachments
Screen Shot 2022-05-19 at 12.45.28 PM.png
Screen Shot 2022-05-19 at 12.45.28 PM.png (12.61 KiB) Viewed 322 times

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Color detection Sending a key press

Post by Rohwedder » 19 May 2022, 07:47

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

Post Reply

Return to “Ask for Help (v1)”