PixelSearch + PostMessage Click

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

PixelSearch + PostMessage Click

24 Jul 2017, 13:00

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 
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: PixelSearch + PostMessage Click

24 Jul 2017, 16:09

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
Last edited by jeeswg on 27 Aug 2017, 16:55, edited 2 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Trigg
Posts: 97
Joined: 07 Apr 2017, 19:43

Re: PixelSearch + PostMessage Click

25 Jul 2017, 08:12

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: rc76 and 190 guests