Sending Arrow Keys to Popen

前端 未结 2 651
臣服心动
臣服心动 2021-01-05 17:29

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

from subprocess import,          


        
2条回答
  •  死守一世寂寞
    2021-01-05 17:46

    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.

提交回复
热议问题