juechafun/04-归档/归档知识/RAG-MaixCam-触摸事件.md

1.1 KiB
Raw Blame History


#领域/MaixCam

一句话描述

[MaixCam 获取触摸事件]


更新时间2026-05-25

MaixCam 触摸事件获取参数配置备忘

用途说明

记录 MaixCam 设备触摸屏接口调用规范,用于读取屏幕坐标与按压状态,适配分辨率 552 x 368 的图形界面交互开发。

配置明细

基础环境提示

  • 屏幕分辨率为 552 x 368,菜单绘制后不建议进行图像缩放等操作

最小实现代码

from maix import touchscreen

ts = touchscreen.TouchScreen()
x, y, pressed = ts.read()

样例程序

from maix import touchscreen, app, time, display, image

ts = touchscreen.TouchScreen()
disp = display.Display()

img = image.Image(disp.width(), disp.height())

def menu_update(img):
    img.draw_string(8, 12, "< Exit", image.COLOR_WHITE)
    img.draw_rect(0, 0, 100, 100, image.COLOR_WHITE, 2)

while not app.need_exit():
    x, y, pressed = ts.read()
    if x > 0 and x < 100 and y > 0 and y < 100:
        app.set_exit_flag(True)
    
    menu_update(img) # 更新菜单
    disp.show(img)   # 屏幕显示