除非我在 xwindows 中,否则 Pygame.MOUSEBUTTONDOWN 坐标已关闭 [英] Pygame.MOUSEBUTTONDOWN coordinates are off unless i'm in xwindows

查看:60
本文介绍了除非我在 xwindows 中,否则 Pygame.MOUSEBUTTONDOWN 坐标已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从控制台加载我的 pygame 代码,它会错误地读取触摸屏坐标,但是如果我启动到 xwindows,它会正确读取它们.

If I load my pygame code from the console, it is reading the touchscreen coordinates wrong, but if I boot into xwindows, it reads them correctly.

我已经进入并校准了触摸屏,如果我从控制台运行 evtest,我会得到正确的坐标.只有在 python 中,它才会返回不正确的触摸坐标.

I've gone in and calibrated the touch screen, and if I run evtest from the console, I am getting the correct coordinates back. It is only within python that it is returning the incorrect coordinates of the touch.

有什么我想告诉 python 如何校准的吗?

Is there something i'm missing to tell python how to calibrate?

import sys, pygame
pygame.init()

black = 0, 0, 0
size = width, height = 1280, 800
screen = pygame.display.set_mode(size)


while 1:
        for event in pygame.event.get():
                if event.type == pygame.QUIT: sys.exit()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                        print(pygame.mouse.get_pos())
        screen.fill(black)

推荐答案

当不在 X11 下运行时,PyGame 将利用 SDL 进行视频(帧缓冲区)和鼠标/触摸输入(输入事件).使用触摸屏(而不是传统鼠标)SDL 通常会报告未校准和(可能?)未旋转的坐标,除非您使用 TSLIB.

When not running under X11, PyGame will leverage SDL both for video (frame buffer) and mouse/touch input (input events). With a touchscreen (as opposed to a traditional mouse) SDL will usually report uncalibrated and (possibly?) un-rotated coordinates unless you make it use TSLIB.

确保您拥有所有需要的零碎:

Make sure you have all the needed bits and pieces:

apt-get install tslib libts-bin

现在通过在启动 Python 脚本之前设置一些环境变量来告诉 SDL 使用它:

Now tell SDL to use it by setting some environment variables before you start your Python script:

export SDL_FBDEV=/dev/fb1
export SDL_MOUSEDRV=TSLIB
export SDL_MOUSEDEV=/dev/input/touchscreen
./my_cool_program.py

或者您可以在 Python 脚本中本地"执行此操作 - 这不会影响 Python 进程之外的环境变量:

Or you can do that "locally" in your Python script - this won't affect environment variables outside of the Python process:

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

这几乎可以解决所有问题,包括 [触摸] 屏幕方向.您应该注意检查系统的 fbdev 和输入设备路径的正确性.

This should take care of almost everything, including [touch]screen orientation. You should take care of checking the correctness of fbdev and input device paths for you system.

如果你想提高触摸屏的精度,你可以校准它:

If you want to improve the touchscreen precision you can calibrate it:

TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_calibrate

...你也可以测试一下:

...and you can also test it:

TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/touchscreen ts_test

校准数据保存在 /etc/pointercal 中,因此您无需在重新启动系统时重新校准.

Calibration data is saved to /etc/pointercal so you don't have to re-calibrate when you reboot the system.

这篇关于除非我在 xwindows 中,否则 Pygame.MOUSEBUTTONDOWN 坐标已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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