Manuel Fankhänel
Manuel Fankhänel

Reputation: 11

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

Upvotes: 0

Views: 499

Answers (2)

oskar
oskar

Reputation: 657

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])

Upvotes: 0

Manuel Fankhänel
Manuel Fankhänel

Reputation: 11

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) 

Upvotes: 1

Related Questions