From f67f14d8a05f0aa25387bedb73c6af04dc2e4b71 Mon Sep 17 00:00:00 2001 From: zhiguo Date: Thu, 30 Apr 2026 10:16:04 +0800 Subject: [PATCH] fix: replace keyboard lib with imgui in tiny video game example The `keyboard` library requires root on Linux to read /dev/input devices. Replace it with polyscope's bundled imgui (ImGuiKey_* + IsKeyDown) which works without elevated privileges inside the polyscope render loop. --- examples/4_tiny_video_game/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/4_tiny_video_game/main.py b/examples/4_tiny_video_game/main.py index c9ff728..976425d 100644 --- a/examples/4_tiny_video_game/main.py +++ b/examples/4_tiny_video_game/main.py @@ -1,7 +1,6 @@ import numpy as np import polyscope as ps from polyscope import imgui -import keyboard from uipc import view from uipc import Engine, World, Scene, Animation from uipc import Vector3, Vector2, Transform, Logger, Quaternion, AngleAxis @@ -16,11 +15,17 @@ ps.init() Logger.set_level(Logger.Level.Warn) +_KEY_MAP = { + "w": imgui.ImGuiKey_W, "s": imgui.ImGuiKey_S, "d": imgui.ImGuiKey_D, + "a": imgui.ImGuiKey_A, "e": imgui.ImGuiKey_E, "q": imgui.ImGuiKey_Q, +} + class IO: @staticmethod def is_key_down(key_str:str): - return keyboard.is_pressed(key_str.lower()) - + key = _KEY_MAP.get(key_str.lower()) + return imgui.IsKeyDown(key) if key is not None else False + @staticmethod def movement(): w = 1.0 if IO.is_key_down("W") else 0.0