View Single Post
  #4  
Old 11-17-2007, 07:03 PM
jukofyork jukofyork is offline
Senior Member
 
Join Date: Sep 2004
Location: Leeds, UK.
Posts: 2,551
Default Re: prevent focus stealing in Vista? messing up my AHK script

[ QUOTE ]
I found a decent workaround in case anyone has the same problem. When I first register a button click on a table i use MouseGetPos,,tableId to retrieve the ID # of the table under the cursor. Then, before I send a command like ControlClick or whatnot, I first use WinActivate, %tableId% to activate the table that was under the mousepointer when the click initially happened.

It's still possible that another table will steal focus in between the time the table is activated and the time the click is sent (in between 2 lines of code) but it is extremely unlikely.

[/ QUOTE ]
Have you tried to use my PostLeftClick() function. It posts a mouse click into the window's message queue which means it can't mess up and click in the wrong window:

<font class="small">Code:</font><hr /><pre>
PostLeftClick(x, y, table_id, activate=1) {
; ### JUK: Send the down left click, then the mouse-up messages.
; NOTE: This is relative to the top left of the client area and NOT the top left of the
; window (ie: It *doesn't* include the title-bar like AHK's MouseClick does!!!).
If activate
WinActivate, ahk_id%table_id%
PostMessage, 0x201, 0x0001, ((y&lt;&lt;16)^x), , ahk_id%table_id%
PostMessage, 0x202 , 0, ((y&lt;&lt;16)^x), , ahk_id%table_id%
}
</pre><hr />

Juk [img]/images/graemlins/smile.gif[/img]
Reply With Quote