Page 1 of 1

PixelSearch + PostMessage Click

Posted: 24 Jul 2017, 13:00
by Trigg
Is it possible to use PixelSearch and PostMessage to click on something in Chrome? I cannot seem to figure out why this isn't working.

Code: Select all

;https://autohotkey.com/board/topic/60285-clicking-on-non-active-window-using-postmessagesendmessage/

PixelSearch, Px, Py, 1, 1, 1920, 1080, 0x3296FF, 0, Fast

  ControlGet, chwnd, Hwnd,, Edit1, Personal inbox - Google Chrome
  PostClick(%Px%, %Py%, chwnd)
  return

PostClick(x, y, hwnd) 
{
  lParam := x & 0xFFFF | (y & 0xFFFF) << 16 
  PostMessage, 0x201, 1, %lParam%,, ahk_id %hwnd% ;WM_LBUTTONDOWN 
  PostMessage, 0x202, 0, %lParam%,, ahk_id %hwnd% ;WM_LBUTTONUP 
}

Re: PixelSearch + PostMessage Click

Posted: 24 Jul 2017, 16:09
by jeeswg
Hopefully this will work for you. Cheers.

Code: Select all

q:: ;post click
CoordMode, Pixel, Screen
;testing on MS Paint (Windows XP version), looking for aqua colour:
;draw some aqua pixels, then change the primary colour,
;watch the aqua pixels get replaced as you trigger the hotkey
PixelSearch, vPosX, vPosY, 1, 1, 1920, 1080, 0x00FFFF, 0, Fast RGB
;if !hWnd := DllCall("WindowFromPoint", Int,vPosX, Int,vPosY, Ptr)
if !hWnd := DllCall("WindowFromPoint", UInt64,(vPosX&0xFFFFFFFF)|(vPosY<<32), Ptr)
	return
VarSetCapacity(POINT, 8, 0)
NumPut(vPosX, POINT, 0, "Int"), NumPut(vPosY, POINT, 4, "Int")
DllCall("user32\ScreenToClient", Ptr,hWnd, Ptr,&POINT)
vPosX := NumGet(POINT, 0, "Int"), vPosY := NumGet(POINT, 4, "Int")
;ToolTip, % vPosX " " vPosY

;test that the coordinates are correct by using WM_MOUSEMOVE:
;PostMessage, 0x200, 0, % vPosX&0xFFFF|vPosY<<16,, % "ahk_id " hWnd ;WM_MOUSEMOVE := 0x200
PostMessage, 0x201, 0, % vPosX&0xFFFF|vPosY<<16,, % "ahk_id " hWnd ;WM_LBUTTONDOWN := 0x201
PostMessage, 0x202, 0, % vPosX&0xFFFF|vPosY<<16,, % "ahk_id " hWnd ;WM_LBUTTONUP := 0x202
return

Re: PixelSearch + PostMessage Click

Posted: 25 Jul 2017, 08:12
by Trigg
This works, thank you!
jeeswg wrote:Hopefully this will work for you. Cheers.

Code: Select all

q:: ;post click
CoordMode, Pixel, Screen
;testing on MS Paint (Windows XP version), looking for aqua colour:
;draw some aqua pixels, then change the primary colour,
;watch the aqua pixels get replaced as you trigger the hotkey
PixelSearch, vPosX, vPosY, 1, 1, 1920, 1080, 0x00FFFF, 0, Fast ; RGB
if !hWnd := DllCall("WindowFromPoint", Int,vPosX, Int,vPosY, Ptr)
	return
VarSetCapacity(POINT, 8, 0)
NumPut(vPosX, POINT, 0, "Int"), NumPut(vPosY, POINT, 4, "Int")
DllCall("user32\ScreenToClient", Ptr,hWnd, Ptr,&POINT)
vPosX := NumGet(POINT, 0, "Int"), vPosY := NumGet(POINT, 4, "Int")
;ToolTip, % vPosX " " vPosY

;test that the coordinates are correct by using WM_MOUSEMOVE:
;PostMessage, 0x200, 0, % vPosX&0xFFFF|vPosY<<16,, % "ahk_id " hWnd ;WM_MOUSEMOVE := 0x200
PostMessage, 0x201, 0, % vPosX&0xFFFF|vPosY<<16,, % "ahk_id " hWnd ;WM_LBUTTONDOWN := 0x201
PostMessage, 0x202, 0, % vPosX&0xFFFF|vPosY<<16,, % "ahk_id " hWnd ;WM_LBUTTONUP := 0x202
return