Question

I am running my script once every X hours with Python, this is done via RDP. After I close out the RDP (I assume) the screen "locks" on the computer. When trying to move my mouse with the following code I get an error

def mclick(x,y):
    win32api.SetCursorPos((x,y))
    time.sleep(0.5)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

The error I get when the script runs after I have closed the RDP connection:

File "x", line x, in mclick
    win32api.SetCursorPos((x,y))
pywintypes.error: (0, 'SetCursorPos', 'No error message is available')

I assume this is because the RDP connection has closed so it has no where to click, aside from constantly having this RDP connection alive how would I get this to run?

Was it helpful?

Solution

Calls to SetCursorPos fail when the workstation is locked. That is by design, and is a security feature. You simply need to catch and ignore the errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top