为什么我的 event.getKeys() 内存缓冲区没有清除?

Why is my event.getKeys() memory buffer not clearing?

背景:

我有一项任务是使用 VLCMovieStim 播放视频,并且每一帧都在连续的双极尺度上收集评分。给出它的外观的想法。 event.getKeys() 跟踪按下 2 或 3 按钮但尚未释放的时间。当满足这些条件时,变量 keys 会更改值。对于 keys 由于按键而采用 'LEFT' 或 'RIGHT' 值的每一帧,比例将在相应方向上增加 1%。释放键时,event.clearEvents() 清除内存缓冲区,有效地将 keys 的值更改回 'STOP'。

问题:

当等级量表震荡次数足够多时,它就会断裂。从秤当前位于的任何位置,它都会前进到两个极点之一并停留在该终端位置,无论之后存在什么按钮状态。 print() 函数已经证明 keys 的值确实在每一帧都成功重置,但似乎一旦到达条件,感觉将条件 keys 更改为 'LEFT' 或 'RIGHT' 已经满足,尽管没有按下任何按钮。看起来虽然我正在更改 keys 的值但我实际上并没有清除事件内存,但我不知道为什么会这样。我假设我的逻辑一定有缺陷,但经过大约一周的讨论后,我不知所措:

kb = keyboard.Keyboard()
        if kb.status == STARTED:
            keys = 'STOP'
            # When the left key is pressed and not released, keys = LEFT
            # If either boolean is 'True', simply holding down the button will not yield continuous incrementing in the rating
            if len(kb.getKeys([keyLeft], waitRelease = True, clear = True)) == 0 or len(kb.getKeys([keyRight], waitRelease = True, clear = True)) == 0:
                keys = 'STOP'
                if len(kb.getKeys([keyLeft], waitRelease = False, clear = False)) > 0:
                    keys = 'LEFT'
                    if len(kb.getKeys([keyLeft], waitRelease = True, clear = False)) > 0:
                        kb.clearEvents()
                elif len(kb.getKeys([keyRight], waitRelease = False, clear = False)) > 0:
                    keys = 'RIGHT'
                    if len(kb.getKeys([keyRight], waitRelease = True, clear = False)) > 0:
                        kb.clearEvents()
            if keys == 'LEFT':
                y1 -= round(0.005,3)
                y1 = round(y1,3)
                y3 = ((y1)/2)
                if y1 < 0:
                    keyCount += 1
                if keyCount > 100:
                    keyCount = 100
                if y1 >0:
                    keyCount -= 1
                if y1 == 0.000:
                    keyCount = 0
                if y1 <= -0.5:
                    y1 = -0.5
                    keyCount = 100
            if keys == 'RIGHT':
                y1 += round(0.005,3)
                y1 = round(y1,3)
                y3 = ((y1)/2)
                if y1 > 0:
                    keyCount += 1
                if keyCount > 100:
                    keyCount = 100
                if y1 <0:
                    keyCount -= 1
                if y1 == 0.000:
                    keyCount = 0
                if y1 >= 0.5:
                    y1 = 0.5
                    keyCount = 100 

为了共享可复制的代码而不是发送垃圾邮件 post,我已经隔离了必要的代码并将其与必要的刺激一起提供,here.

提前感谢您的宝贵时间!

我想出了自己的解决方案。我只是简单地更改了条件逻辑,以指定如果当前仅按下一个键,则键只能采用方向值。这个问题似乎总是在改变方向时产生,所以通过限制一个人快速改变方向的能力,我似乎​​已经解决了这个问题。为了额外的保险,我指定如果刻度当前处于任一极点,则键不能采用方向值。几个小时以来,我一直在尝试破解脚本,但一直没有成功。当然,在它再次发生之前我无法确定,但祈祷吧。

        if kb.status == STARTED:
           
            # At the start of the loop, we check whether the scale is at either of its poles, 
            # and if so, we reset the keys variable and clear the event log.
            if abs(y1) >= 0.5:
                keys = 'STOP'
                kb.clearEvents()

            # If the left button is being pressed, and the right button is not being 
            # pressed, and the scale is not currently at the left pole, change the 
            # value of keys to LEFT. These additional conditionals are crucial for me.
            if len(kb.getKeys([keyLeft], waitRelease = False, clear = False)) == 1 and len(kb.getKeys([keyRight], waitRelease = False, clear = False)) != 1 and y1 > -0.5:
                keys = 'LEFT'

                # Once the key is released, clear the memory buffer and change 
                # the value of keys to STOP
                if len(kb.getKeys([keyLeft], waitRelease = True, clear = False)) > 0:
                     keys = 'STOP'
                     kb.clearEvents()

            # Just as above, except for the right key. 
            elif len(kb.getKeys([keyRight], waitRelease = False, clear = False)) == 1 and len(kb.getKeys([keyLeft], waitRelease = False, clear = False)) != 1 and y1 < 0.5 :
                keys = 'RIGHT'
                if len(kb.getKeys([keyRight], waitRelease = True, clear = False)) > 0:
                        keys = 'STOP'
                        kb.clearEvents()