Im using python 3.7 and windows 10
I got this script:
import pyautogui
pyautogui.click()
It runs fine on my computer untill i until i launch a specific program (program A), then it completely stop working. It does not only not work when this program (program A) is highlighted but also in every other program (program B, C, ..) that is currently running. Before program A is started my code works fine in the other programs (B ,C ,...).
I do not get any errors, the code still executes as expected but without actually doing a mouse click.
one thing worth noting is that if i use pyautogui.moveTo(x,y) the mouse do still move.
Any ideas on why this is happening? and/or how I can work around / solve the problem ?
Note:
I have seen answers where the .click() function doesen't work within specific applications, but in my case it stops working within the entire os (any application) as long as Program A is running.
Note #2:
i have tried this on an other computer as-well, problem is the same.
Note #3:
I do run everything as an admin
Related
I've been working on a small script in python to press some keys when I press one specific (I created a macro).
All works fine since I try to use it in any other application like for example a videogame or other programs.
The problem is that it only executes once, and then the only way it executes again is chainging to my IDE tab (Visual studio code) and returning back to the application, and this is quite annoying.
Any idea about it and how to solve that window problem? Here is the code
def macros():
t=threading.Timer(0.1,macros)
t.start()
if keyboard.is_pressed('k'):
keyboard.press('e')
keyboard.press('q')
print("active")
So I have a sikuli script running which monitors and executes a said action every 10 minutes continuously. However for various reasons sometimes the run is interrupted and there is no way to alert if the script stops running.
So I tried running a python script, which would monitor the window of the sikuli IDE. When the script runs, the window is no longer visible. So if the window is visible again the python script would run a batch file which would trigger the alert required. The following is the script which I made from seeing other examples here in this site:
WindowName = "SikulixIDE 1.1.3 - C:\\Users\\TestUser\\Downloads\\testing2.sikuli"
while True:
try:
if win32ui.FindWindow(None, WindowName):
subprocess.call([r'C:\Users\TestUser\Documents\notification.bat'])
break
except win32ui.error:
#print("its not running!")
continue
The problem I am running into with the above code is, even when the sikuli script is running and the IDE window (one with the WindowName) is not actually visible to me, it still finds it and goes into the if block. I am not sure what's going wrong here, if the window is not visible in Task Manager, FindWindow shouldn't be able to find it, correct?
I would say you are trying to do this in very complicated way.
I will strongly suggest to look at '-r' option of sikuli and to write only one sikuli script that will handle exceptions by itself and will not need monitoring.
In this case if you really need additional monitoring for the script it will be easier since you can look for process with specific command line(instead of visible window)
I've done a reasonable amount of coding with the libtcod library, both the C# and python wrappers. My current setup is KUbuntu 14.10, python 2.7.8, and libtcod 1.5.2.
I've made a few programs that work fine, but the latest I've just started doesn't seem to want to allow me to close the console window.
I can send a CTRL+C from the console that I run the program from, and it will close, but, no amount of clicking on the window's "x" button, or Alt+F4s seem to work.
My code is as follows:
'''
justclose.py
'''
import sys
import time
import libtcodpy as libtcod
libtcod.console_set_custom_font(b'lucida12x12_gs_tc.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(50,50, "The ever-present window", False)
libtcod.console_flush()
while not libtcod.console_is_window_closed():
time.sleep(1)
sys.exit
When I run the program, the console comes up, as expected, and sits around waiting for console_is_window_closed to return true, which it never does. I'm not sure where the problem lies. I can run other programs that use the same initialisation code, and same while loop and which respond just fine to me clicking the close button on the console window.
I've tried looking through an strace of the process, but, I'm not sure I'm up to the task of deciphering it. Nothing looked immediately out of the ordinary.
I'd like some advice on how to track down what's going wrong. Thanks.
EDIT: specifically, I'd like to know how I can check that the close window event is propagating at all, and if so, how far, where it's getting trapped/ignored, that sort of thing. When I run through strace, I see absolutely nothing happening when I click the close button. Is there some better way to debug this?
Replace time.sleep(1) with libtcod.console_check_for_keypress(). When the program sleeps 1 millisecond for each iteration, the program can not respond when you press X. It exits when you press CTRL+C because the program receives the SIGINT signal and it exits immediately. Replacing time.sleep(1) with libtcod.console_check_for_keypress() makes the program check the key pressed on the keyboard, if there is one. That way, the program doesn't block the execution.
I have recently started to learn Python 3 and have run into an issue while trying to learn how to debug using IDLE. I have created a basic program following a tutorial, which then explains how to use the debugger. However, I keep running into an issue while stepping through the code, which the tutorial does not explain (I have followed the instructions perfectly) nor does hours of searching on the internet. Basically if I step while already inside a function, usually following print() the debugger steps into pyshell.py, specifically, PyShell.py:1285: write() if i step out of pyshell, the debugger will simple step back in as soon as I try to move on, if this is repeated the step, go, etc buttons will grey out.
Any help will be greatly appreciated.
Thanks.
pyshell.py file opens during the debugging process when the function that is under review is found in Python's library - for example print() or input(). If you want to bypass this file/process click Over and it will step over this review of the function in Python's library.
In Python 3.4, I had the same problem. My tutorial is from Invent with Python by Al Sweigart, chapter 7.
New file editor windows such as pyshell.py and random.pyopen when built-in functions are called, such as input(), print(), random.randint(), etc. Then the STEP button starts stepping through the file it opened.
If you click OVER, you will have to click it several times, but if you click OUT, pyshell.py will close immediately and you'll be back in the original file you were trying to debug.
Also, I encountered problems confusing this one--the grayed-out buttons you mentioned--if I forgot to click in the shell and give input when the program asked. I tried Wing IDE and it didn't run the program correctly, although the program has no bugs. So I googled the problem, and there was no indication that IDLE is broken or useless.
Therefore, I kept trying till the OUT button in the IDLE debugger solved the problem.
A real newbie question here.
I'm using IDLE 2.7.2 on OSX 10.7.2 and reading Zelle's Python:Programming. I haven't programmed since the 80's, so after going through the command line stuff, I'm excited to dive into Objects. I grab his graphics.py file and copy it into documents (this seems like the default location for IDLE) and start up IDLE.
He then suggests a few commands into the shell:
from graphics import *
win = GraphWin() #which opens a graphics window with no problem
He then goes on to have you draw some lines and shapes in the window. Those graphics show up just fine in the window.
Here's my problem. If I try to mouse over the graphics window, I get the Mac pinwheel. Moving the window doesn't help. So the window seems like it's crashing (though IDLE is doing fine), but strangely, if I keep entering commands into IDLE, the shapes keep drawing normally in the window.
Am I doing something wrong? Is this normal? Thanks,
Henry
Idle runs the python commands you enter in another process, so it's reasonable to expect this "lock up" behavior to be different between the program controlled window and Idle.
What's probably going on, though is that everything is fine, but you have not yet started the event loop in the program you're typing in. The operating system notices that the program is not emptying out its event queue when you mouse over it (which creates lots of events) and it's helpfully informing you (by way of the pinwheel) that the program seems to be busy.
You will likely reach a point later in the tutorial where you do start the event loop, and the pinwheel will magically go away.