Python:_on_keyboard_down函数传递值奇怪的字符,如ā,Ă,ą

时间:2018-09-04 06:41:35

标签: python python-2.7 kivy

我正在def _on_keyboard_downpython-2.7中使用kivy。当我在键盘上按1,2,3时,然后打印text奇怪的字符,如ā,Ă,±。有人可以帮我吗?

 def _on_keyboard_down(self, instance, keyboard, keycode, text, modifiers):
        print(text)

1 个答案:

答案 0 :(得分:1)

替换

_on_keyboard_down(self, instance, keyboard, keycode, text, modifiers):

_on_keyboard_down(self, window, keycode, scancode, text, modifiers):

输出

The keycode 49 have been pressed
 - text is '1'
 - modifiers are []
 - window= <kivy.core.window.window_sdl2.WindowSDL object at 0x7f91dc381180>
 - scancode= 30

The keycode 257 have been pressed
 - text is 'ā'
 - modifiers are []
 - window= <kivy.core.window.window_sdl2.WindowSDL object at 0x7f91dc381180>
 - scancode= 89

The key 258 have been pressed
 - text is 'Ă'
 - modifiers are []
 - window= <kivy.core.window.window_sdl2.WindowSDL object at 0x7f91dc381180>
 - scancode= 90 

已按下键码259      -文字为“ă”      -修饰符为[]      -窗口=      -scancode = 91

数字键盘

按下数字1的键盘时,键码为49。

数字键盘

按下NumPad键盘时,键码= 257表示数字1,键码= 258表示数字2,键码= 259表示数字3,依此类推。