Note that there are some explanatory texts on larger screens.

plurals
  1. POwxpython: Set Cursor to Absolute Screen Location And Click
    text
    copied!<p>I'm having a little trouble trying to get WarpPointer to work out appropriately for me. The scenario I'm trying to do is akin to recording a user's clicks and then replaying them on the screen. I've been able to record the screen motions and clicks without any issues; however, I'm stumbling when it comes to replaying what the user recorded.</p> <pre><code>def MoveCursorAndClick(self, e): # get the current screen position sp = self.GetPosition() p = self.getNextPosition() # returned in absolute x,y from screen rec self.WarpPointer(p.x - sp[0], p.y - sp[1]) # wx.PostEvent(EVT_LEFT_DOWN, self.GetId()) </code></pre> <p>Obviously, the above code is incorrect because WarpPointer appears to work within the window only and not the full screen. Attempting to base the coordinated off of the functioning window as well proves to be troublesome because they always seem to be off in the Y direction by about 50 pix. My only current assumption is I'm making this harder than it needs to be and there's a better why I'm not seeing due to my inexperience with wxpython.</p> <p>Additionally, the busted PostEvent line is the only thing I've managed to google across that looks like the right thing for sending a mouse click to something that may or may not be another window. Is that even the right direction?</p> <p><strong>Updated</strong> As mentioned below, there's not a good cross platform way to accomplish this. Here's what I did (found various places on the internet):</p> <pre><code>def ClickScreenPositon(self, x, y): win32api.SetCursorPos((x,y)) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload