繁体   English   中英

(Python 3 | LINUX)有没有办法使用 termios.tcflush 刷新文件中的输入?

[英](Python 3 | LINUX) Is there a way to use termios.tcflush to flush inputs from a file?

我创建了一个模拟人打字的程序。 我收到错误: termios.error: (25, 'Inappropriate ioctl for device')我认为发生这种情况是因为我将一个文本文件作为代码的输入。 这是我正在使用的库和一些代码:

from pynput.keyboard import Key, Controller
from termios import tcflush, TCIFLUSH
from sys import stdin, stdout
from time import sleep
from random import randint

keyboard = Controller()

def typeS(self, string):
    for i, character in enumerate(string):
        try:
            self.press(character)
            sleep(randint(1, 3) * 0.07)
            self.release(character)
            sleep(randint(1, 3) * 0.07)
        except ValueError:
            raise self.InvalidCharacterException(i, character)

word = input()
timings = input()

word = word.split(",")
timings = timings.split(",")

print(f"word = {word}")
print(f"timings = {timings}")

typeS(keyboard, word)

tcflush(stdin, TCIFLUSH)

和我正在使用的命令行命令: python3 faketyper.py < fakeprofile-1.txt我需要使用 tcflush 以便当代码按下一个键时,存储的东西不会稍后打印到命令行。 忽略您在代码中看到的任何语法或错误,因为我没有复制并粘贴每一行。 我的主要目标是找出如何使用 tcflush(或其他东西)刷新输入,以便在代码运行完成后不会向命令行打印任何内容。

在评论中回答。 只需将“stdin”更改为“stdout”。 向蒂姆·罗伯茨 (Tim Roberts) 大声疾呼他的洞察力。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM