0

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!

Alex C
  • 16,624
  • 18
  • 66
  • 98
vossmalte
  • 174
  • 2
  • 2
  • 16

2 Answers2

1

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
user3412027
  • 83
  • 1
  • 6
1

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.
venpa
  • 4,268
  • 21
  • 23