Python win32api mouse control losing focus - python

I'm using win32api in a Python script to control mouse movements. It's working fantastic, but as soon as I click (I also generate click events) outside my Python shell/IDE, all my mouse events immediately stop. If I click my shell/IDE again, control is restored.
It seems like mouse control is only working when my Python shell or IDE is the "active" window - is there any way to retain mouse control even after Python is sent to the background?

Turns out this was not a Python issue, but was an issue with the device I was using to generate mouse movements. A separate API call was required to allow this device to push events when its owner was out of focus.

Related

How do I send key presses and mouse movements to an application running in the background? (In Python)

Ok, so what I want to do is allow my program to send mouse movements and keypresses (both mouse and keyboard) to a particular task without having to be tabbed into the task so I can do other things on my computer with the mouse and keyboard while the task runs. Is it possible to do this relatively simply with existing python modules?
example of what I want to do:
task='application name'
task.leftclick
task.moveX(int)
task.moveY(int)
task.keypress(r)
All while being able to use my mouse and keyboard normally on a different application.
Thanks for the help in advance!
(Python3.6)
For anyone who happens upon this post, I found https://pypi.org/project/ahk/ I haven't looked into it fully but either you can use this or create an auto hotkey script and just call that with you python code to achieve what I wanted to do in the question.

MacOS - Python 3.7 - GUI mouse control for DirectX 8 (2003) app - unable to simulate mouse clicks but I can simulate keyboard entry

I am trying to control an old DirectX application from a Python script. The application concerned is from 2003 (ish). Launches full screen (in a Desktop space) in OSX and requires the mouse be 'freed' via a command. Once the mouse is freed you can use it normally.
I have tried scripting to simulate a mouse click. I have used AppleScript and Python to no avail.
Keyboard simulation does work. For example the first thing any scripting does is swap into the relevant desktop space with a shortcut then hit a keyboard shortcut in the app. This works.
Moving the mouse around the app with scripting works.
However the following will not work.
1) Simulated clicks from code.
2) Turning on mouse keys and simulating a keyboard click in code. Note if I turn on mouse keys and manually hit the mouse click key in the app this does work.
Doesn't work -
import pyautogui
pyyautogui.click()
from pynput import Button,Controller
mouse = Controller()
mouse.click(Button.left, 2)
So basically simulating the keyboard works in the app but I am struggling to simulate a mouse click (moving the mouse works fine). Any ideas?
are you saying you want to write with pyautogui? you can use this:
import pyautogui
pyautogui.write('An example')

Detect if mouse is Waiting or Busy using python

I am creating a script in Python 2.7. The script automates mouse clicks, within an application.
There are instances that after a mouse click, the mouse cursor will be "Waiting", I want to wait until the mouse cursor changes back to normal before I go to the next step within the code.
Is it possible within python to detect whether the mouse is waiting?

How to get python to constantly check for key combinations even if it is in the background?

I was thinking of coding a script that will run in the background of my computer that will detect key combinations to start specific tasks.
For example, the user presses Ctrl+Alt+F1 then the browser starts. However, I cannot seem to find a way to detect these combinations while the script is running in the background.
I thought of using a .pyw extension for my script, but that makes the script not interact-able.
If anyone needs to know, my OS is Windows 10.
I think the pyHook library is what you're looking for:
The pyHook package provides callbacks for global mouse and keyboard events in Windows. Python applications register event handlers for user input events such as left mouse down, left mouse up, key down, etc. and set the keyboard and/or mouse hook.

Mouse left click doesn't fire wx.EVT_BUTTON in Linux. Works in Windows

I'm trying to port my wxpython GUI to Linux from Windows and it's not behaving the same. Specifically, a mouse left click is not firing the wx.EVT_BUTTON event. When I left click it only appears to select the control. If I click spacebar it animates the button and the event is triggered.
This is my first time using wxpython in Linux, so I created a test UI frame with a wx.Button. In this case, the behavior works as expected. My bindings and events are the same in both applications, so I'm not quite sure what's up. The only difference is my original application has a parent wx.Frame with multiple children of type wx.Panel, whereas my test application is a solitary wx.Frame.

Categories

Resources