我想在我的应用程序中添加外部键盘操作。键盘在Mac / Kivy环境下工作正常,但是在 iPhone (通过 toolchain.py 发送)上,键盘输入事件丢失了 在出现TextInput 对话框之后。 在以下示例中,可以通过“ Enter”键将MyLayout2切换到MyLayout1,但是不能通过“ Enter”将MyLayout1切换到MyLayout2。我认为这可能是由于SDL2版本引起的,所以我将其更新为最新版本2.0.10,但没有任何更改。是SDL2的 bug ?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import NumericProperty
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.textinput import TextInput
from kivy.core.window import Window
sm = ScreenManager()
class MyLayout1(BoxLayout):
pass
class MyLayout2(BoxLayout):
pass
class MyScreen(Screen):
dialog_number = 0
def __init__(self, **kwargs):
super(MyScreen, self).__init__(**kwargs)
self.gridlayout = None
self.gridlayout = MyLayout2()
self.add_widget(self.gridlayout)
Window.bind(on_key_up=self._keyup)
def _keyup(self,*args):
print(args[2])
if (args[2] == 40):
if self.dialog_number == 0:
self.button2_clicked()
elif self.dialog_number == 1:
self.button1_clicked()
def button1_clicked(self, *args):
if self.gridlayout is not None:
self.remove_widget(self.gridlayout)
self.gridlayout = MyLayout2()
self.add_widget(self.gridlayout)
self.dialog_number = 0
def button2_clicked(self, *args):
if self.gridlayout is not None:
self.remove_widget(self.gridlayout)
self.gridlayout = MyLayout1()
self.add_widget(self.gridlayout)
self.dialog_number = 1
class myApp(App):
def build(self):
self.myscreen = MyScreen(name = 'myscreen')
sm.add_widget(self.myscreen)
sm.current = 'myscreen'
return sm
if __name__ == '__main__':
myApp().run()
<MyScreen>:
BoxLayout:
orientation: 'vertical'
padding: 10,40,10,40
spacing: 40
<MyLayout1>:
Button1:
id: btn1
text: '<MyLayout1> OK or ENTER key'
on_release: root.parent.button1_clicked()
<MyLayout2>:
txtinput: txtinput
orientation: 'vertical'
TextInput:
id: txtinput
text: ''
multiline: False
focus: True
button2:
id:Button2
text: '<MyLayout2> OK or ENTER key'
on_release: root.parent.button2_clicked()
<Button0@Button>:
<Button1@Button>:
<button2@Button>: