Detect if mouse is Waiting or Busy using python - 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?

Related

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')

Psychopy on Surface Pro 6: Can touchscreen be used to press AND hold a button similar to a mouse click?

SPECS:
Using PsychoPy v1.90.3
Window 10 Pro 6 running Windows 10
BACKGROUND:
I am programming a touchscreen task to use with children (reference image linked below). In the task, children need to press and hold the red 'home' button for 1.5 seconds at the bottom of the screen to advance through trials(i.e., opening the windows at the top of the screen to reveal boxes they can open). I also collect the time of the mouse button being pressed and released (used to calculate response time).
I originally programmed this task on my desktop using a mouse, so pressing and holding the home button was no problem using this code:
mouse = event.Mouse(visible=True)
while not homePressed:
if mouse.isPressedIn(home) and home.contains(mouse):
core.wait(1.5, hogCPUperiod=1.5) ## when home button is pressed, wait for 1.5s
if mouse.isPressedIn(home) and home.contains(mouse): ## check if home button is still pressed
homePressed=True
When I tried to run the task on the Surface Pro I ran into a problem with the touchscreen not registering a 'press and hold'. I've learned that the touchscreen doesn't register mouse clicks unless the screen has been pressed AND released because a press and hold could be (1) a right click or (2) a swipe. I've tried disabling the 'press and hold' registering as a right-click option on the Surface Pro but this has not solved my issue.
QUESTIONS:
Is there a way to get the Surface Pro or PsychoPy to register a press and hold on the touchscreen the same way it does using a mouse so children press the 'home' button down to continue the trials?
If yes, can I get PsychoPy to output the 'press' (when the screen is touched) and 'release' (when the touch is no longer present) output the same way it does for a mouse click?
If this cannot be accomplished with the PsychoPy library, are there possible python solutions outside of PsychoPy I could try?
SOLUTIONS TRIED:
using only home.contains(mouse) solution found here
resetting the mouse location solution found here
fixing the 'double tap' issue solution found here
Disabling the Surface Pro's right-click function for touch
task set up image
You could try and write a loop that checks the hold time yourself. For example, in a gaze contingent study we have loops to check how long someone has been looking at something, similar to your "hold" variable.
tCueOn=expClock.getTime()
while True:
curtime=expClock.getTime()-tCueOn
eventType=eyelink.getNextData()
sample=eyelink.getNewestSample()
<<... a bunch of sample processing cut out ...>>
if curtime>=cueTime:
break
In your case you detect the press, get the time, and enter the loop where you repeatedly check the press status is still true and that the time is less than 1.5. When it exceeds 1.5 you break the loop, or if they let up for less than 1.5 you return to whereever you need to in your use case. You might find it convenient to bundle this logic in a function that you could just call whenever "press home" is true.
Hope this helps, cheers.

Is it possible to move and click the mouse in an inactive window with Python?

Is there a way to make the mouse move to certain coordinates and click inside of a window that might be in the background or behind another window without losing focus.
The idea is to let it work in the background while I'm using the computer for something else.
I'm working with Python on Windows 10.

Python win32api mouse control losing focus

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.

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