python - 当我与远程桌面断开连接时,PyKeyboard.tap_key() 不起作用

标签 python windows winapi remote-desktop

我有一个程序,它使用 PyKeyboard.tap_key() 将击键发送到我正在自动化的另一个应用程序(不幸的是,该应用程序无法以任何其他方式自动化)。我在远程 Windows 计算机上运行它,通过远程桌面访问该计算机。

PyKeyboard.tap_key() 在我连接时运行良好,但如果我从远程桌面 session 断开连接,则不再传递击键。

另一个问题:断开远程 session 是否相当于“注销->切换用户”?我认为问题是用户未登录(即使 session 正在运行)。

最佳答案

看来这不是Python相关的问题。 SendInput() 也会发生这种情况(这可能是 Python 使用的 WINAPI 函数)。

来自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.

关于python - 当我与远程桌面断开连接时,PyKeyboard.tap_key() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26848714/

相关文章:

python - 使用 Python 解析文本文件中的文本 block

python - 获取明天日期的最简洁和最 Pythonic 的方式?

windows - 从 Git Gui (windows) 推送到远程 Git 存储库的问题

winapi - 在当前的 Windows 版本中,Win32 API 仍然是 "native"吗?

c++ - 进程 ID 和进程名称

windows - NASM ReadConsoleA 或 WriteConsoleA 缓冲区调试问题

python - 将 Pandas 数据框中的整数二值化

java - Python 将字节写入 Redis,但 Java 读取它时出现异常

windows - 从命令行替换字符串中的多个字符

c# - 如何从添加/删除程序控制面板获取图标