community
community copied to clipboard
Keyboard - on_key_down triggered twice
Versions
- Python: 3.4
- OS: Kivy Pie Version: 0.9b (jessie) http://kivypie.mitako.eu/kivy-download.html
- Kivy: 1.9.2-dev0
- Kivy installation method: -
- Device: Raspberry 3b
Description
All keyboard events are triggered twice. (Code is example code from documentation)
When I press keys "a", "b", "c" output is following:
Purge log fired. Analysing... Purge finished! The key (97, 'a') have been pressed
- text is 'a'
- modifiers are [] (48, 48) The key (97, 'a') have been pressed
- text is 'a'
- modifiers are [] The key (98, 'b') have been pressed
- text is 'b'
- modifiers are [] The key (98, 'b') have been pressed
- text is 'b'
- modifiers are [] The key (99, 'c') have been pressed
- text is 'c'
- modifiers are [] The key (99, 'c') have been pressed
- text is 'c'
- modifiers are []
Code and Logs
import kivy
kivy.require('1.9.2')
from kivy.core.window import Window
from kivy.uix.widget import Widget
class MyKeyboardListener(Widget):
def __init__(self, **kwargs):
super(MyKeyboardListener, self).__init__(**kwargs)
self._keyboard = Window.request_keyboard(
self._keyboard_closed, self, 'text')
if self._keyboard.widget:
# If it exists, this widget is a VKeyboard object which you can use
# to change the keyboard layout.
pass
self._keyboard.bind(on_key_down=self._on_keyboard_down)
def _keyboard_closed(self):
print('My keyboard have been closed!')
self._keyboard.unbind(on_key_down=self._on_keyboard_down)
self._keyboard = None
def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
print('The key', keycode, 'have been pressed')
print(' - text is %r' % text)
print(' - modifiers are %r' % modifiers)
# Keycode is composed of an integer + a string
# If we hit escape, release the keyboard
if keycode[1] == 'escape':
keyboard.release()
# Return True to accept the key. Otherwise, it will be used by
# the system.
return True
if __name__ == '__main__':
from kivy.base import runTouchApp
runTouchApp(MyKeyboardListener())
Duplicate of #4253, try switching to SDL2 provider.