pexpect发送光标移动器

2024-09-28 22:11:05 发布

您现在位置:Python中文网/ 问答频道 /正文

你怎么能发送光标移动像上,下,左,右键与pexpect。下面的例子是自动化elinks,它使用向上/向下键选择页面上的不同链接。在

from pexpect import spawn
child = spawn('elinks http://python.org')
#what goes here to send down key
child.interact()

Tags: fromorgimportchildhttp链接页面what
2条回答

对向上(^[[A)或向下(^[[B)使用转义序列如何。在

child.send("\033[A")  # up
child.send("\033[B")  # down

下面的脚本包含所有四个光标移动的代码,并举例说明如何在pexpect中使用它。要发现任何键入文本的确切字符串序列,可以使用get_键.py下面的脚本。在

KEY_UP = '\x1b[A'
KEY_DOWN = '\x1b[B'
KEY_RIGHT = '\x1b[C'
KEY_LEFT = '\x1b[D'
child.sendline(KEY_DOWN * 5)  #send five key downs

得到_键.py

^{2}$

相关问题 更多 >