Python诅咒Flush最新x stdin

2024-09-30 12:27:52 发布

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

我正在开发一个小python脚本,它使用curses读取终端的stdin。当用户按下键时,movement_smallstep应该递增,以便在x'重复'之后进行更快的总体移动。每次按键都会调用此函数。由于移动和函数的UI更改不同步,用户通常会“超调”目标,因此我想刷新一些诅咒的stdin。在

def movement_manager(step,repeats,key):
    global old_key #remembering the n-1 pressed key of stdin
    global input_repeats #remembering how often the key was pressed
    global movement_smallstep #movement for ui change
    if key != old_key:
        input_key = key
        input_repeats = 0
        movement_smallstep = 1
    if (input_repeats > repeats):
        movement_smallstep+=1
        #Flush the newest x stdin inputs of the queue here
    input_repeats+=1
    return movement_smallstep

例如,用户按“A”键23次。在

^{pr2}$

Tags: ofthekey函数用户inputifstdin

热门问题