Q: Pixel Search Fast How to click colors only when button is pressed? using gdip how to use gdip in my code ?

loop{
CoordMode, Pixel, Screen
KeyWait, space, D
PixelSearch, FoundX, FoundY, 317, 236, 323, 245, 0xFFFF00, 50, Fast RGB
If (ErrorLevel = 0){
sendinput, {Lbutton down}
sleep, 30
sendinput, {lbutton up}
}


}
return
I have codes that can help but I don't know how to do it

1- CODE
SetBatchLines, -1

#Include Gdip.ahk

pToken := Gdip_Startup()

; Screen area ("X|Y|Width|Height")
pBitmap := Gdip_BitmapFromScreen("500|600|300|100")

; Read RGB color from pixel x290 y65
ARGB := Gdip_GetPixel( pBitmap, 290, 65 )
pixelColor := ARGBtoRGB( ARGB )
MsgBox, % pixelColor

; Read RGB color from pixel x167 y90
ARGB := Gdip_GetPixel( pBitmap, 167, 90 )
pixelColor := ARGBtoRGB( ARGB )
MsgBox, % pixelColor


Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)

ARGBtoRGB( ARGB ) {
VarSetCapacity( RGB,6,0 )
DllCall( "msvcrt.dll\sprintf", Str,RGB, Str,"%06X", UInt,ARGB<<8 )
Return "0x" RGB
}

2 - CODE
color1 := 0xFFFF00

FastPixel := new FastPixelSearch(0, 0, A_ScreenWidth, A_ScreenHeight)
res1 := FastPixel.Search(color1)

class FastPixelSearch
{
__New(x, y, w, h) {
this.hBM := this.Api.HBitmapFromScreen(x, y, w, h, pvBits)
this.pvBits := pvBits
this.w := w
this.size := w*h
}

Search(colorRGB) {
static bin := 0
(!bin && bin := this.Api.GetBin())
(!(colorRGB >> 24) && colorRGB |= 0xFF000000)
byte := DllCall(bin, "ptr", this.pvBits, "UInt", this.size, "UInt", colorRGB, "Int")
if (byte == this.pvBits + this.size * 4)
Return false
offset := (byte - this.pvBits)//4
Return {x: mod(offset, this.w), y: offset//this.w}
}

class Api
{
GetBin() {
static PAGE_EXECUTE_READWRITE := 0x40, CRYPT_STRING_BASE64 := 0x1
; C source code - https://godbolt.org/z/oYx39nr5s
code := A_PtrSize = 8 ? "idJIjQSRSDnBcw9EOQF1BInI6wZIg8EE6+zD"
: "VYnli1UIi0UMi00QjQSCOcJzDTkKdQSJ0OsFg8IE6+9dww=="
size := StrLen( RTrim(code, "=") )*3//4
bin := DllCall("GlobalAlloc", "UInt", 0, "Ptr", size, "Ptr")
DllCall("VirtualProtect", "Ptr", bin, "Ptr", size, "UInt", PAGE_EXECUTE_READWRITE, "UIntP", old:=0)
DllCall("crypt32\CryptStringToBinary", "Str", code, "UInt", 0, "UInt", CRYPT_STRING_BASE64
, "Ptr", bin, "UIntP", size, "Ptr", 0, "Ptr", 0)
Return bin
}

HBitmapFromScreen(X, Y, W, H, ByRef pvBits) {
static rop := (SRCCOPY := 0x00CC0020) | (CAPTUREBLT := 0x40000000)
hDC := DllCall("GetDC", "Ptr", 0, "Ptr")
hBM := this.CreateDIBSection(W, H, hDC, pvBits)
hMDC := DllCall("CreateCompatibleDC", "Ptr", hDC, "Ptr")
hObj := DllCall("SelectObject", "Ptr", hMDC, "Ptr", hBM, "Ptr")
DllCall("BitBlt", "Ptr", hMDC, "Int", 0, "Int", 0, "Int", W, "Int", H
, "Ptr", hDC, "Int", X, "Int", Y, "UInt", rop)
DllCall("SelectObject", "Ptr", hMDC, "Ptr", hObj, "Ptr")
DllCall("DeleteDC", "Ptr", hMDC)
DllCall("ReleaseDC", "Ptr", 0, "Ptr", hDC)
Return hBM
}

CreateDIBSection(w, h, hDC, ByRef pvBits) {
VarSetCapacity(BITMAPINFO, 40, 0)
NumPut(40, BITMAPINFO,  0)
NumPut( w, BITMAPINFO,  4)
NumPut(-h, BITMAPINFO,  8)
NumPut( 1, BITMAPINFO, 12)
NumPut(32, BITMAPINFO, 14)
hBM := DllCall("CreateDIBSection", "Ptr", hDC, "Ptr", &BITMAPINFO, "UInt", 0
, "PtrP", pvBits, "Ptr", 0, "UInt", 0, "Ptr")
return hBM
}
}

__Delete() {
DllCall("DeleteObject", "Ptr", this.hBM)
}
}


*^NumPad0::ExitApp

