I have written a small function that gets the current position of the mouse cursor and prints it to a command line. However I want to also be able to press a key at any point and it will run a function. However if there is no key press I want it to continue running the function and printing the position of the mouse...
Code for the mouse pos:
while True :
x, y = win32api.GetCursorPos()
data = (str(x) + " " + str(y))
print data
time.sleep(0.1)
The code I added for the key press was this:
while True :
if msvcrt.getch() == "h" :
data = "h"
else :
x, y = win32api.GetCursorPos()
data = (str(x) + " " + str(y))
print data
time.sleep(0.1)
However the problem with this is that it waits until I press a key to run the get cursor position. It also doesn't register a key press of h when the program is unfocused which is a necessity.
Thanks for any help,
Ryan.