使用适用于Linux的Python模拟按键事件 [英] Simulating Key Press event using Python for Linux

查看:394
本文介绍了使用适用于Linux的Python模拟按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个脚本来自动运行特定模型.当模型失败时,它将等待用户输入(Enter键).我可以检测到模型何时失败,但是无法使用python(在linux上)模拟按键事件. Windows具有SendKeys库来执行此操作,但我想知道Linux上是否有类似的python库.

I am writing a script to automate running a particular model. When the model fails, it waits for a user input (Enter key). I can detect when the model has failed, but I am not able to use python (on linux) to simulate a key press event. Windows has the SendKeys library to do this but I was wondering if there is a similar library for python on linux.

谢谢!

推荐答案

如果模型"以图形方式(使用X窗口系统)运行,则建议使用 xsendkeycode .如果它以文本方式运行(在终端窗口中),则 pexpect .

If the "model" is running graphically (with the X window system), the already-suggested xsendkey is a possibility, or xsendkeycode. If it's running textually (in a terminal window), then pexpect.

这篇关于使用适用于Linux的Python模拟按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆