I am looking for a way to run mouse and keyboard events in a minimized window, simple as that - the code does something in a specific window, while my computer is free - I can search the web and do whatever; I need Python 2 specifically, but open for 3 suggestions too; This is for automatization of certain tasks I have, I managed to make it work while my computer is in use, but now I need to run it in the background.
Thank you in advance.
Related
I use python and pynput to automate my mouse.
But obviously, it is impossible to use the computer at the same time for other things. So I'm looking for a solution to either automate a "second" virtual mouse or to just send mouse clicks to a specific window (active or inactive) on Windows 10 without actually using the real mouse.
You can use pyautogui to automate keyboard and mouse actions; but if you are using the keyboard and mouse it will interfere with these commands. the same could be said about adding another mouse; it doesn't add a second OS pointer; it only creates another (at times conflicting) control over that pointer.
I am about to switch from Windows to Ubuntu. Since my mouse keeps doing multiple clicks each time I press the middle mouse button, I used AutoHotkey under Windows to add a delay after each click. This worked fine. Now under Ubuntu I want to use AutoKey to do the same. Autokey uses Python for its scripts though.
Here is the AutoHotkey script:
MButton::
If (A_TimeSincePriorHotkey < 200)
Return
Send {MButton}
Return
Currently, (as of version 0.95.4), this is not possible from within AutoKey, because it can’t handle mouse buttons as hotkeys.
This stackoverflow question may be of help: Triggering AutoKey Script via Mouse Button - How To?
I am working with a program that collects a lot of data then shows it to you in the program. Unfortunately, the program is poorly designed and requires you to "approve" each bit of data collected manually by clicking a checkbox to approve it. In order to automate this process, I wrote a small script that scans for a checkbox, clicks it, then clicks "next item".
Unfortunately, this requires moving the actual mouse, meaning I can't use my computer until the program has finished. There are other questions that reference automating this with the winapi, however none of these work on Linux. What is a way to automate this on Linux?
You can simply start the program in a separate X server, for example using xvfb with
xvfb-run YOUR_PROGRAM
If you want to wrap just the instrumented program, that's possible too:
export DISPLAY=:42
Xvfb :42
THE_INSTRUMENTED_PROGRAMM
xdotool mousemove 1 1 click 1 # your instrumentation goes here
I have a small GUI application that listens for network messages so a user can update some info and accept it. This is in a production factory environment and used for interacting with a specific piece of physical hardware (over serial in some cases). The workflow looks like this:
User is interacting with another program (5250 Green Screen)
They enter a certain keybinding that sends a UDP message to a Tkinter GUI
The Tkinter GUI does a deiconify()
User edits data, accepts (Enter) and it does an iconify()
My issue is that on windows XP, the GUI does not become active when I do the deiconify and conversely does not fall back to the prior window on iconify. I have tried some things I found in other questions such as:
Setting the Tk GUI as top.. self.wm_attributes("-topmost", 1)
Trying to set/force focus... self.focus_set() and self.focus_force()
Although the window is visible with the first, I can not seem to get it to be the active window so that the user can type in it without "clicking" on it to activate. The same is true for releasing the "focus" so that the active window becomes the one they were previously on (5250).
It seems like an issue that others also have had but I have not been able to find anything that works. Is there a programmatic way to get the window activated and release it when done?
Unfortunately, after a week there have been no answers and I was not able to find a direct way to do this with Tkinter. I did find a way to solve the problem though and it appears to work consistently. Here are the steps I took to make the screens activate:
Install pywin32.
Create a function that activates the tk app.
Create a function that activates the 5250.
Then each time I do a iconify/deiconify I also run the function to activate the appropriate screen. The code that activates the tk window looks like this:
def activate_self(self):
""" Activate this window. """
shell = win32com.client.Dispatch('WScript.Shell')
shell.AppActivate(str(self.title))
shell = None
The code that activates the caller is a little ugly since it has to guess the title but is the same basic concept.
I'm developing a rather big GUI with Tkinter for my cocktail-robot and now I'm trying to disable the mouse for a few seconds, so that no click on the screen will cause any event.
The reason why I need to do this is that the programm crashes if there're to much incoming events. Because I'm using time.sleep() for a few seconds, Windows thinks that the programm crashed and asks whether it should be closed.
Is there any possibilty to do that? Can I just bind the whole screen to "< Button-1 >"
Btw. the GUI is based on this structure:
Switch between two frames in tkinter
I'm looking forward to your help! Thanks