发送箭头键到Popen [英] Sending Arrow Keys to Popen

查看:119
本文介绍了发送箭头键到Popen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以通过write发送到stdin

来将可打印输入发送到subprocess es

from subprocess import, Popen, PIPE
proc = Popen([command, goes, here], stdin=PIPE)
proc.stdin.write("m")

我该如何发送诸如箭头键输入,空格,返回键或退格键之类的输入?

解决方案

我发现有人试图解决相反的问题,创建了一个可以识别箭头键的程序: http://compgroups.net/comp.unix.programmer/如何发送箭头键到popen-child/537480 上面写着:

"\x1B[A" for up
"\x1B[B" for down

因此,如果\ x1B是转义符,则只需在[A处向上,[B处向下,[C处右,D处左等等.

看看 http://en.wikipedia.org/wiki/ANSI_escape_sequences 以获得不同代码的列表.

I know that it's possible to send printable input to subprocesses by writeing to their stdin

from subprocess import, Popen, PIPE
proc = Popen([command, goes, here], stdin=PIPE)
proc.stdin.write("m")

How would I go about sending input such as arrow key presses, space, return, or backspace?

解决方案

I found someone who was trying to solve the opposite problem, create a program that could recognize the arrow keys: Recognizing arrow keys with stdin

I also found http://compgroups.net/comp.unix.programmer/how-to-send-up-arrow-key-to-popen-child/537480 which says:

"\x1B[A" for up
"\x1B[B" for down

So if \x1B is the escape character than you just append [A for up, [B for down, [C for right and [D for left and so on.

Take a look at http://en.wikipedia.org/wiki/ANSI_escape_sequences for a list of the different codes.

这篇关于发送箭头键到Popen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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