I have this code which uses the change in mouse cursor position to detect mouse movement:
import win32api
from time import sleep
savedpos = win32api.GetCursorPos()
count = 0
while(True):
curpos = win32api.GetCursorPos()
if savedpos != curpos:
count = count +1
savedpos = curpos
print("Mouse Movement # ", count)
sleep(0.05)
The problem is that when the mouse cursor is in one of the corners of the screen, my Python code may not recognize mouse movement. For example, if the mouse cursor is in the upper left corner of the screen, moving my physical mouse up and/or left will not have any effect on my Python code (it won't print "Mouse Movement #").
Can someone please help me get my Python code to recognize physical mouse movement even when the mouse cursor is unable to move on the screen?
(1,1)
when you detect the cursor is at(0,0)
, so that you can detect mouse movement again. – Arnitaarno