Thank Brian, it works !!!

Marc

Le 15 mai 06 à 07:23, Brian Rathbone a écrit :



arael wrote:

for a click in (100, 100)

But the click comes always at the mouse position and not in 100, 100

Why ?


This is a bit more complicated, and it took me a good long while to figure this out, but here is the solution. You need to do a conversion of twips per pixel in order to get the correct coordiantes.

Create these two functions in your window or a module:

Private Function twipsperpixelx(x as integer) As integer
 dim m as memoryblock
 dim i as integer
Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As integer Declare Function ClientToScreen Lib "user32" Alias "ClientToScreen" (hwnd As integer, lpPoint As ptr) As integer
 m = newmemoryBlock(8)
 m.long(0) = x
 m.long(4) = 0
 i = ClientToScreen(GetDesktopWindow(),m)
 if i <> 0 then
   return m.long(0)
 else
   return 0
 end
End Function

Private Function twipsperpixely(y as integer) As integer
 dim m as memoryblock
 dim i as integer
Declare Function GetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As integer Declare Function ClientToScreen Lib "user32" Alias "ClientToScreen" (hwnd As integer, lpPoint As ptr) As integer
 m = newmemoryBlock(8)
 m.long(0) = 0
 m.long(4) = y
 i = ClientToScreen(GetDesktopWindow(),m)
 if i <> 0 then
   return m.long(4)
 else
   return 0
 end
End Function

Then do something like this for your click:

dim x,y as integer
 const MOUSEEVENTF_ABSOLUTE = &h8000
 const MOUSEEVENTF_MOVE = &h1
 const MOUSEEVENTF_LEFTDOWN = &h2
 const MOUSEEVENTF_LEFTUP = &h4
 const MOUSEEVENTF_RIGHTDOWN = &h8
 const MOUSEEVENTF_RIGHTUP = &h10
Declare sub mouse_event Lib "user32" Alias "mouse_event" (dwFlags As integer, dx As integer, dy As integer, cButtons As integer, dwExtraInfo As integer)
       x = 100
       y = 100
       x = round(twipsperpixelx(x) * 65535 / screen(0).width)
       y = round(twipsperpixely(y) * 65535 / screen(0).height)
mouse_event bitwisexor (MOUSEEVENTF_MOVE,MOUSEEVENTF_ABSOLUTE),x,y,0,0
       mouse_event MOUSEEVENTF_LEFTDOWN,0,0,0,0
       mouse_event MOUSEEVENTF_LEFTUP,0,0,0,0

hth,

Brian
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to