【问题标题】:kivy is not detecting touch inputkivy 没有检测到触摸输入
【发布时间】:2020-06-08 13:40:09
【问题描述】:

我已经在我的 Ubuntu 上安装了 kivy 并连接了一个触摸屏,但是当我触摸屏幕时 kivy 没有检测到。

检测鼠标点击没问题,只是触摸不起作用。

我已经在 config.ini 中进行了更改:`

mouse = mouse; 
mtdev_%(name)s = probesysfs,provider=mtdev; hid_%(name)s = probesysfs,provider=hidinput 

这是我的代码:

from kivy.app import App

从 kivy.uix.widget 导入小部件

类 TouchInput(Widget):

def on_touch_down(self, touch):
    print(touch)
def on_touch_move(self, touch):
    print(touch)
def on_touch_up(self, touch):
    print("RELEASED!",touch)

类 SimpleKivy4(App):

def build(self):
    return TouchInput()

如果 name == "ma​​in": SimpleKivy4().run()

有人知道为什么 kivy 没有检测到我的触摸输入吗?

提前谢谢你。

【问题讨论】:

  • 我不确定你为什么要标记 ros,这不是 ros 问题。如果你想在 python 中监听一个运动事件,you have to bind your callback to Window;当你得到它们时,我会通过 print()'ing 事件来测试它。
  • 你的意思是if __name__ == "__main__"
  • 是的,就是这个意思

标签: python ubuntu kivy touch


【解决方案1】:

虽然您已经定义了 on_touch_*(self, touch) 函数,但仅仅定义它是不够的。 Window 模块有一个 on_touch_* 方法,但它目前绑定到 None。它是 Window 模块,而不是您自己的类/小部件,它管理您的应用程序的整个窗口,调用诸如运动和触摸之类的回调。 Under the docs for input.motionevent,它有以下关于如何监听(使用你的回调)的动作/触摸事件:

def on_touch_down(self, touch):
    # Receives a motion event with the [pos] profile
    pass
Window.bind(on_touch_down=on_touch_down)

您错过了Window.bind(window_method=my_function) 电话。

【讨论】:

  • 谢谢我已经添加了它,但是 kivy 仍然只检测到鼠标点击,而不是当我用手指触摸显示屏时。触摸设备没问题我证明了,只有kivy不明白。
  • 那你要指定输入设备; cf ProvidersConfig 用于输入。