PyGame 和触摸屏 [英] PyGame and touchscreen

查看:104
本文介绍了PyGame 和触摸屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个带有按钮的 pygame GUI 界面,当用户点击它们时会激活这些按钮.当我使用真正的鼠标时,GUI 运行良好,但是当我在 PITFT (https://www.adafruit.com/product/1601 ),按钮对点击没有反应(即使我使用比我的手指更硬的材料,如手写笔).

I've made a pygame GUI interface with buttons who are activated when the user click on them. The GUI works well when i'm using my real mouse but when I run the GUI on the PITFT (https://www.adafruit.com/product/1601 ), buttons do not respond to clicks ( even if i use a harder material than my finger like a stylus ).

所以问题是:Pygame 点击事件是否与 PITFT 兼容,或者是否有一种特殊"事件为它制作?

So the question is : Are Pygame click event compatible with the PITFT or are there a kind of "special" event made for it ?

这是我在代码中使用的当前鼠标事件:

Here is the current mouse event i use in my code :

def run(self):
  """Lance la boucle principale pour gérer les événements
  """
  while True:
     event = pygame.event.wait()

     if event.type == MOUSEBUTTONDOWN and event.button == 1 and not self.keep_level_2:
        self.click(event.pos)

     elif event.type == MOUSEBUTTONUP and event.button == 1:
        self.release(event.pos)`

我在网上搜索,发现要使用 PiTft,需要添加以下几行:

I shearch on the internet and found that in order to use the PiTft, you need to add the following lines :

os.environ['SDL_VIDEODRIVER'] = 'fbcon'
os.environ["SDL_FBDEV"] = "/dev/fb1"
os.environ["SDL_MOUSEDEV"] = "/dev/input/touchscreen"
os.environ["SDL_MOUSEDRV"] = "TSLIB"

所以我尝试添加它们,但触摸屏仍然没有响应.

So i've tried adding them but the touchscreen is still not responding.

另外,什么时候程序运行,我不能退出(CTRL C和escape不起作用).

Also, when to program run, i can't quit it ( CTRL C and escape don't work ).

注意:我的代码没有在 python 3 中运行

Note : My code is not running in python 3

推荐答案

您是否检查过您的/dev/input/touchscreen 是否链接"到了正确的模块?检查 evtest/dev/input/touchscreen 并检查它在使用屏幕、键盘或鼠标时是否有任何反应!

Did you check that your /dev/input/touchscreen is "linked" to the right module? Check evtest /dev/input/touchscreen and check if it does anything when using the screen, or the keyboard, or the mouse!

如果发生这种情况,您应该再次执行安装过程.

If this is happening you should follow the install procedure again.

这篇关于PyGame 和触摸屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆