发送到 Citrix 应用程序时在 Python 脚本中模拟硬件按键(SendKeys 不起作用)

Imitate hardware keypress in Python script when sending to Citrix app (SendKeys does not work)

过去两天我花了很多时间试图找出如何将 Ctrl-Space 发送到 Citrix 上的应用程序 运行。我的脚本是基于 Python 的,我已经尝试了从 SendKeys 到 Pywin32 和 SendInput() 的各种解决方案,以及这些帖子中概述的解决方案以及我早已关闭的其他解决方案: Generate Keyboard events in python SendInput

问题是这些似乎都在发送 Citrix 无法识别的文本或模拟按键。我似乎需要做的是模拟硬件按键而不是直接发送到应用程序。许多解决方案都是用 C (或类似的)编写的,我不熟悉。

有人对此有基于 Python 的解决方案吗?或者在 Python 中包含 C 或 VB.NET 代码的方法? VB 列出的解决方案 here 可能有效也可能无效,但我不确定如何将其功能导入我基于 Python 的脚本。

如有任何建议,我们将不胜感激!

编辑:为了强调直接硬件操作而不是模拟按键的需要,我向 Citrix 应用程序发送了以下命令:

        SendInput(Keyboard(VK_RETURN))
        SendInput(Keyboard(VK_RETURN, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_CAPITAL))
        SendInput(Keyboard(KEY_L))
        SendInput(Keyboard(KEY_L, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_CAPITAL, KEYEVENTF_KEYUP))
        SendInput(Keyboard(KEY_0))
        SendInput(Keyboard(KEY_0, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_SPACE))
        SendInput(Keyboard(VK_SPACE, KEYEVENTF_KEYUP))
        SendInput(Keyboard(KEY_A))
        SendInput(Keyboard(KEY_A, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_BACK))
        SendInput(Keyboard(VK_BACK, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_CONTROL))
        SendInput(Keyboard(KEY_A))
        SendInput(Keyboard(KEY_A, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_CONTROL, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_LCONTROL))
        SendInput(Keyboard(KEY_V))
        SendInput(Keyboard(KEY_V, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_CONTROL, KEYEVENTF_KEYUP))
        SendInput(Keyboard(VK_RETURN))
        SendInput(Keyboard(VK_RETURN, KEYEVENTF_KEYUP))

我在应用程序中得到以下输出:=tbd7w\=

我终于找到了有用的东西:Keyboard

这已成功向 Citrix 应用程序发送击键,包括修饰符。如上所述发送 CTRL-SPACE 就像 Keyboard.send('ctrl-space') 一样简单。希望这对某人有所帮助!