My application sends a mouse click to an area of the screen outside my console window using win32api.mouse_event
. This causes my window to lose focus so I can't detect key presses using msvcrt.kbhit.
My question is, how to implement something like this with the console window not being visible/active?
EDIT:
Here is example code. This is just a basic console version. If the console disappears, set it so that it stays on top. Once it clicks outside of the console (100,100), pressing the Esc key will not break out of loop. How would one implement a break for a problem such as this?
import msvcrt, win32api, win32con
pixelx = 100
pixely = 100
win32api.SetCursorPos((pixelx,pixely))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,pixelx,pixely,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,pixelx,pixely,0,0)
while 1:
print 'Testing..'
# body of the loop ...
if msvcrt.kbhit():
if ord(msvcrt.getch()) == 27:
break