[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mouse control

On 7/10/19 4:11 AM, Alexander Vergun wrote:
> I am coding a voice assistant under Python 3.7, Windows 7. I am using 
> PYcharm and libraries such as PYSimpleGUI, mouse, keyboard etc. 
> Everything works except for the mouse control and probably keyboard, the 
> problem is following, when I run the script under PYcharm, the script 
> can control mouse only within PYcharm editor, but when the other window 
> is on the top, the script cannot control the mouse, and the same happens 
> when the script runs under the Python console. There is only one way to 
> make script control the mouse - I have to manually click on the window 
> which was opened by the script only then the script controls the mouse. 
> I tried to call win32gui.SetCapture without any effect.
> Does anyone have an idea how to handle this? Thank you very much,

Are you asking to be able to start a Python application in one window, 
which will control the mouse and keyboard in other concurrent 
applications' windows?

I don't use MS-Windows, but don't think this is possible (under any OpSys).

As you say "and probably keyboard": imagine typing and having the text 
appear in every open window/application? If you don't want that, how do 
you indicate which one should accept the input? Answer: "focus" = the 
'target' for any typing is the application/window which currently has focus.

Extending those thoughts to the mouse doesn't quite ring-true, because 
I'm currently in 'this' window writing an email message, yet the mouse 
will cheerfully scroll the window 'below'. Is that the sort of action 
you wish?

In my experience, the Python application, including "mouse", only 
operates in "user space" and within the one window. If we can extend 
Python's power and dominion, I'll be interested to learn...

Meantime, there are demo snippets which follow the mouse, printing its 
coordinates. Using one of those, what happens to the coordinates when 
the mouse is moved outside of the Python application's window?

BTW you may like to take a look at PyAutoGUI, if only because it has 
been more recently updated. It may also help by bringing 'everything' 
under one import rather than the multiple packages (listed above):
Regards =dn