Key hold doesn't return true always

from direct.showbase.ShowBase import ShowBase
from direct.task import Task

class Game(ShowBase):

def __init__(self):
    super().__init__()

    self.keys = {
        "a": False,
    }

    self.accept("a", self.key_down, ["a"])
    self.accept("a-up", self.key_up, ["a"])

    taskMgr.add(self.check_key_state, "check_key_state")

def key_down(self, key):
    self.keys[key] = True

def key_up(self, key):
    self.keys[key] = False

def check_key_state(self, task):
    if self.keys["a"]:
        print("Key 'a' is held down")
    else:
        print("Key 'a' is not held down")
    return Task.cont

game = Game()
game.run()

Am on Ubuntu, when I press and hold the a button after some seconds self.keys[‘a’] becomes false

It alternates

Instead of

Key a is hold down
Key a is hold down
Key a is hold down
....

I get , that’s is after some seconds of holding down a

Key a is hold down
Key a is not hold down
Key a is hold down
Key a is not hold down
Key a is hold down
....

Hmm… That’s very odd!

I’m on Ubuntu myself, and I’m not seeing that behaviour from the code that you posted…

So, let me ask:

  • What version of Ubuntu are you using?
  • What version of Panda are you using?
  • What version of Python are you using?
  • Might it be that there’s an issue with your keyboard?
    • (e.g. If it’s a wireless keyboard, is the battery perhaps running low?)
  • Am using Ubuntu kinectic Kudu, although I was told I needed to upgrade
  • Am using the version 1.11
  • The version of Python? Haven't checked that since am not with my laptop now I can't check, but am sure is the latest there is
  • My keyboard is fine, I can assert that, is not wireless

What happens if you use Panda version 1.10? Perhaps there’s an issue in the bleeding-edge version that isn’t present in the stable version.

If that doesn’t help, then for now at least I don’t know, I’m afraid! Perhaps one of the other forum-members might have another idea! :/

(For reference, I’m using an older version of Ubuntu–18.04–and Panda 1.10.13.)

I can’t add anything useful, but there is something similar in the bugtracker.

1 Like