agassi0430
agassi0430

Reputation: 1195

AHK Script using PostClick and PostMessage

I'm trying to write a simple AHK script to type a few characters and make a few clicks at specific coordinates in a background window, but I can't seem to get it to work, and I'm not finding a lot of information on how to properly use PostClick.

I was able to get this to work using Click when the window is active. Also tried using ControlClick, which seemed to work, except the click was happening on the location where the mouse was rather than the coordinates provided (and also only when the window was activated again).

Can I please have some help / advice on how to get this to work?

Here's my current script:

DetectHiddenWindows On

S:: ;Character to start the loop
pid = 19164 ;Application PID
ControlGet, clickVar, Hwnd , , ahk_pid %pid% ;Specify control for which program

BreakLoop = 0
Loop, 3 {
  if (BreakLoop = 1)
  break 
  Sleep 1000
  PostClick(clickVar,1055,525)
    {
      ControlSend,, 3, ahk_pid %pid%
      lParam := x & 0xFFFF | (y & 0xFFFF) << 16 
      PostMessage, 0x201, , %lParam%, , ahk_pid %pid% ;WM_LBUTTONDOWN 
      PostMessage, 0x202, , %lParam%, , ahk_pid %pid% ;WM_LBUTTONUP 
    }
  Sleep 1500
}

E::
BreakLoop = 1

return

Thanks ahead of time for the help.

Upvotes: 0

Views: 2044

Answers (1)

Reasel
Reasel

Reputation: 93

I am going to assume you are attempting to use this function.

I am unsure how this function works, but I think what you want is something like:

DetectHiddenWindows On

S:: ;Character to start the loop
pid = 19164 ;Application PID
ControlGet, clickVar, Hwnd , , ahk_pid %pid% ;Specify control for which program
WinGetTitle, clickTitle, ahk_pid %pid%
WinGetClass, clickClass, ahk_pid %pid%
BreakLoop = 0
Loop, 3
{
  if (BreakLoop = 1)
  break 
  Sleep 1000
  PostClick(1055,525,clickClass, clickTitle)
  ControlSend,, 3, ahk_pid %pid%
  Sleep 1500
}

E::
BreakLoop = 1

return

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

You need to place the function somewhere in the same file or at least accessible by the current file. You can do #include <script name here>.ahk at the top of your file and place that function as a new file in the same directory if you want.

The function you are trying to use takes in an x and a y for where to click in that window. Then it also takes in a class and title in order to know which window to actually use. Hope this works or helps you in some way.

Upvotes: 1

Related Questions