问题
I have a program that uses PyKeyboard.tap_key() to send keystrokes to another application that I'm automating (the application can't be automated any other way, unfortunately). I run it on a remote Windows computer, which I access through Remote Desktop.
PyKeyboard.tap_key() works well while I'm connected, but if I disconnect from the Remote Desktop session, keystrokes are no longer delivered.
Another question: Is disconnecting the remote session equivalent to "Log off->Switch User"? I assume that the problem is that the user is not logged-in (even though a session is running).
回答1:
It seems that this is not a Python related problem. This happens for SendInput()
as well (which is probably the WINAPI function Python uses anyway).
From this MSDN thread:
Applications are not allowed to send input to the desktop when the computer is locked for security reasons. I tested changing the cursor position when RDP was minimized, but in fact, the mouse cursor is not shown when the session is restored after being minimized, and when it is restored, no cursor visible until the mouse is moved back over the visible area, in which case it is displayed then where the user moves it. In fact, even if the RDP window is restored but the mouse on the host machine is not over the window, the mouse cursor in the RDP window will not be visible. So this is probably not possible either. If you are trying to achieve a specific behavior, there may be another way to do this other than moving the mouse with simulated input though.
来源:https://stackoverflow.com/questions/26848714/pykeyboard-tap-key-doesnt-work-when-i-disconnect-from-remote-desktop