vossmalte
vossmalte

Reputation: 184

How to deactivate keyboard buffer in Windows?

I'm trying to program something using vPython. It's kind of a game, but controls won't work properly.

while True:
    "verarbeitet Maus/Tastatureingaben"        
    if scene.kb:                        # wenn Aktion auf der Tastatur...
        druck=scene.kb.getkey()         # ...Tastendruck speichern!
        # ----Aktionen bei bestimmten Tasten---- #
        if druck == "w":            # vor
            self.bewegen(self.axis)
        elif druck == "s":          # zurück
            self.bewegen(-self.axis)

So there are two main problems:

  1. Two keys can't be pressed at the same time. Only the one pressed latest is working.

  2. If holding a key for about 5 seconds the action will take much longer (I think that's because MS Windows takes a small break after each 'hit').

I hope you can help me!

Upvotes: 0

Views: 232

Answers (2)

venpa
venpa

Reputation: 4318

did you try running your script with -u option:

python -u myscript.py

You can find documentation on this option here

As per document:

Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, 
also put stdin, stdout and stderr in binary mode.

Upvotes: 1

user3412027
user3412027

Reputation: 83

I don't know much about vPython. Does scene.kb return true while keys are pressed? if so, you could do something like this:

keys = []
while scene.kb:
    keys.append(scene.kb.getkey())

if "w" in keys and "s" in keys:
    // do something

Upvotes: 1

Related Questions