Fix "sticky buttons"
@@ -67,6 +67,8 @@ from pyglet import compat_platform
class KeyStateHandler:
"""Simple handler that tracks the state of keys on the keyboard. If a
key is pressed then this handler holds a True value for it.
+ If the window loses focus, all keys will be reset to False to avoid a
+ "sticky" key state.
For example::
@@ -91,6 +93,9 @@ class KeyStateHandler:
def on_key_release(self, symbol, modifiers):
self.data[symbol] = False
+ def on_deactivate(self):
+ self.data.clear()
+
def __getitem__(self, key):
return self.data.get(key, False)
