简体   繁体   中英

How to disable keyboard events in Pygame?

I'm using pygame inside Blender to get multitouch support.

Unfortunately pygame catches all keyboard input which makes it impossible to use shortcuts in Blender.

Can someone help me to unsubscribe from all keyboard events?

Thank you

The problem was, that i used win32gui to render pygame always on top. The with the "win32con.SWP_NOACTIVATE" flag, i could force pygame to be inactive and blender to be active.

    hwnd = pg.display.get_wm_info()["window"]

    rect = win32gui.GetWindowRect(hwnd)
    x = rect[0]
    y = rect[1]
    w = rect[2] - x
    h = rect[3] - y

    win32gui.SetWindowLong (hwnd, win32con.GWL_EXSTYLE, win32gui.GetWindowLong (hwnd, win32con.GWL_EXSTYLE ) | win32con.WS_EX_LAYERED )
    win32gui.SetWindowPos(hwnd, win32con.HWND_TOP, x, y, w, h, win32con.SWP_NOACTIVATE) 

You can block specific events. According to the pygame wiki, this will stop pygame from queuing those events, but I can't test if it stops pygame from requesting keyboard input.

pygame.event.set_blocked([pygame.KEYDOWN, pygame.KEYUP])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM