[python-win32] Pywin32 copying and pasting via mouse/keyboard

Tim Roberts timr at probo.com
Wed Dec 10 01:02:07 CET 2014


Kashif Ali wrote:
> so when i say auto clicker, I mean using pywin32 and its mouse moving
> functions and clicking functions:
>
> |def click(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)
> click(10,10)|

|That's really delicate.  If a field moves in the next browser version,
you're broken.
|

> |However I want to be able to copy text in this automated fashion as
> well. I know there is a clipboard function, however I don't know how
> to copy text to it from the webpage, as i would need to select the
> text and the send it to the clipboard, at which point i can then try
> to get it into a variable.|

Yep, that's the problem.  If it were a normal text box, you could send
EM_SETSEL to set the selection, them WM_COPY to copy to the clipboard. 
But, as I said, the browser window is not a normal text box.  It's
essentially a big bitmap.  Now, continuing to apply the same logic you
have above, you could send LEFTDOWN at the start of the text, then MOVE,
then LEFTUP and the end of the text, then send a Ctrl-C event, but that
means you have to know exactly where the text is.

It might be easier to use COM to pull the HTML text of the page, and
parse that text for the information.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20141209/69ec0280/attachment.html>


More information about the python-win32 mailing list