Code: Select all
~+a::
MouseGetPos,x,y,
a := x-3
b := y-3
c := x+3
d := y+3
PixelSearch,Lx,Ly,a,b,c,d,0x4544A0,0,Fast
if ErrorLevel=0
MouseClick,left,
else
return
Code: Select all
~+a::
MouseGetPos,x,y,
a := x-3
b := y-3
c := x+3
d := y+3
PixelSearch,Lx,Ly,a,b,c,d,0x4544A0,0,Fast
if ErrorLevel=0
MouseClick,left,
else
return
Code: Select all
DllCall("Kernel32\LoadLibrary", "Str", "Gdiplus", "Ptr")
VarSetCapacity(input, 8 + A_PtrSize*2)
, NumPut(0x1, &input + 0, "UInt")
DllCall("Gdiplus\GdiplusStartup", "Ptr*", pToken := 0, "Ptr", &input, "Ptr", 0, "Int")
VarSetCapacity(info, cbSize := 16 + A_PtrSize)
, NumPut(cbSize, &info + 0, "UInt")
if (!DllCall("User32\GetCursorInfo", "Ptr", &info, "UInt")) {
throw (Exception(Format("0x{:X}", A_LastError)))
}
hCursor := NumGet(&info + 8, "Ptr")
if (!hDC := DllCall("Gdi32\CreateCompatibleDC", "Ptr", 0, "Ptr")) {
throw (Exception(Format("0x{:X}", A_LastError)))
}
;* I'm not sure if you can determine the width and height of a cursor/icon so I just went with 20x20 here:
VarSetCapacity(info, 40)
, NumPut(40, &info + 0, "UInt"), NumPut(20, &info + 4, "UInt"), NumPut(-20, &info + 8, "UInt"), NumPut(1, &info + 12, "UShort"), NumPut(32, &info + 14, "UShort"), NumPut(0, &info + 16, "UInt")
if (!hBitmap := DllCall("Gdi32\CreateDIBSection", "Ptr", hDC, "Ptr", &info, "UInt", 0, "Ptr*", 0, "Ptr", 0, "UInt", 0, "Ptr")) {
throw (Exception(Format("0x{:X}", A_LastError)))
}
originalBitmap := DllCall("Gdi32\SelectObject", "Ptr", hDC, "Ptr", hBitmap, "Ptr")
if (!DllCall("User32\DrawIconEx", "Ptr", hDC, "Int", 0, "Int", 0, "Ptr", hCursor, "Int", 0, "Int", 0, "UInt", 0, "Ptr", 0, "UInt", 0x0003)) {
throw (Exception(Format("0x{:X}", A_LastError)))
}
if (status := DllCall("Gdiplus\GdipCreateBitmapFromHBITMAP", "Ptr", hBitmap, "Ptr", 0, "Ptr*", pBitmap := 0, "Int")) { ;* Creates a GDI+ bitmap object from a GDI bitmap handle.
throw (Exception(status))
}
;* Cleanup GDI objects:
DllCall("Gdi32\SelectObject", "Ptr", hDC, "Ptr", originalBitmap, "Ptr")
DllCall("Gdi32\DeleteDC", "Ptr", hDC)
DllCall("Gdi32\DeleteObject", "Ptr", hBitmap, "UInt")
loop, % (20, y := 0) {
loop, % (20, x := 0) {
DllCall("Gdiplus\GdipBitmapGetPixel", "Ptr", pBitmap, "Int", x++, "Int", y, "UInt*", color)
color := Format("{:08X}", color)
}
}
;* Cleanup GDIp objects:
DllCall("Gdiplus\GdipDisposeImage", "Ptr", pBitmap)
;* Shutdown and free library:
DllCall("Gdiplus\GdiplusShutdown", "Ptr", pToken)
DllCall("Kernel32\FreeLibrary", "Ptr", DllCall("Kernel32\GetModuleHandle", "Str", "Gdiplus", "Ptr"), "UInt")
this is so complicated but seems working.Onimuru wrote: ↑11 May 2021, 05:21This is how I would do it:
You have to do a little dance with GDI and GDIp (there may be a way to do it with GDIp alone, idk)Code: Select all
DllCall("Kernel32\LoadLibrary", "Str", "Gdiplus", "Ptr") VarSetCapacity(input, 8 + A_PtrSize*2) , NumPut(0x1, &input + 0, "UInt") DllCall("Gdiplus\GdiplusStartup", "Ptr*", pToken := 0, "Ptr", &input, "Ptr", 0, "Int") VarSetCapacity(info, cbSize := 16 + A_PtrSize) , NumPut(cbSize, &info + 0, "UInt") if (!DllCall("User32\GetCursorInfo", "Ptr", &info, "UInt")) { throw (Exception(Format("0x{:X}", A_LastError))) } hCursor := NumGet(&info + 8, "Ptr") if (!hDC := DllCall("Gdi32\CreateCompatibleDC", "Ptr", 0, "Ptr")) { throw (Exception(Format("0x{:X}", A_LastError))) } ;* I'm not sure if you can determine the width and height of a cursor/icon so I just went with 20x20 here: VarSetCapacity(info, 40) , NumPut(40, &info + 0, "UInt"), NumPut(20, &info + 4, "UInt"), NumPut(-20, &info + 8, "UInt"), NumPut(1, &info + 12, "UShort"), NumPut(32, &info + 14, "UShort"), NumPut(0, &info + 16, "UInt") if (!hBitmap := DllCall("Gdi32\CreateDIBSection", "Ptr", hDC, "Ptr", &info, "UInt", 0, "Ptr*", 0, "Ptr", 0, "UInt", 0, "Ptr")) { throw (Exception(Format("0x{:X}", A_LastError))) } originalBitmap := DllCall("Gdi32\SelectObject", "Ptr", hDC, "Ptr", hBitmap, "Ptr") if (!DllCall("User32\DrawIconEx", "Ptr", hDC, "Int", 0, "Int", 0, "Ptr", hCursor, "Int", 0, "Int", 0, "UInt", 0, "Ptr", 0, "UInt", 0x0003)) { throw (Exception(Format("0x{:X}", A_LastError))) } if (status := DllCall("Gdiplus\GdipCreateBitmapFromHBITMAP", "Ptr", hBitmap, "Ptr", 0, "Ptr*", pBitmap := 0, "Int")) { ;* Creates a GDI+ bitmap object from a GDI bitmap handle. throw (Exception(status)) } ;* Cleanup GDI objects: DllCall("Gdi32\SelectObject", "Ptr", hDC, "Ptr", originalBitmap, "Ptr") DllCall("Gdi32\DeleteDC", "Ptr", hDC) DllCall("Gdi32\DeleteObject", "Ptr", hBitmap, "UInt") loop, % (20, y := 0) { loop, % (20, x := 0) { DllCall("Gdiplus\GdipBitmapGetPixel", "Ptr", pBitmap, "Int", x++, "Int", y, "UInt*", color) color := Format("{:08X}", color) } } ;* Cleanup GDIp objects: DllCall("Gdiplus\GdipDisposeImage", "Ptr", pBitmap) ;* Shutdown and free library: DllCall("Gdiplus\GdiplusShutdown", "Ptr", pToken) DllCall("Kernel32\FreeLibrary", "Ptr", DllCall("Kernel32\GetModuleHandle", "Str", "Gdiplus", "Ptr"), "UInt")
Code: Select all
ErrorFromMessage(messageID) {
if (!(length := DllCall("Kernel32\FormatMessage", "UInt", 0x1100 ;? 0x1100 = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER
, "Ptr", 0, "UInt", messageID, "UInt", 0, "Ptr*", buffer := 0, "UInt", 0, "Ptr", 0, "Int"))) {
return (ErrorFromMessage(DllCall("Kernel32\GetLastError")))
}
message := StrGet(buffer, length - 2) ;* Account for the newline and carriage return characters.
DllCall("Kernel32\LocalFree", "Ptr", buffer)
return (Exception(Format("0x{:X}", messageID), -1, message))
}
Code: Select all
if (!DllCall("User32\DrawIconEx", "Ptr", hDC, "Int", 0, "Int", 0, "Ptr", hCursor, "Int", 0, "Int", 0, "UInt", 0, "Ptr", 0, "UInt", 0x0003)) {
throw (ErrorFromMessage(A_LastError))
}
ok i see.Thank you for your help.Let me find out myself