0

I want to use pygame-menu on a raspberry pi with rotary encoders. When I post up/down events from the encoder callback to pygame, it does not seem compatible. The menu does not react. The same code can post non-keyup/down events successfully. For example:

pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'unicode': '', 'key': 274, 'mod': 0, 'scancode': 108})) # no menu movement
pygame.event.post(pygame.event.Event(pygame.QUIT, {})) # works as expected

Is there a way to simulate keyboard events that can operate the menu?

pygame is at 1.9.6, pygame-menu is 4.1.6

barbazoo
  • 977
  • 5
  • 11

1 Answers1

1

As revealed in https://github.com/ppizarror/pygame-menu/issues/359 pygame checks every key event if there's a corresponding keypress. Drops the event if no match found. The logic can be bypassed with the test=True attribute, as demonstrated in the pygame-menu unit test cases. The following modification allows the proper keydown event injection:

pygame.event.post(pygame.event.Event(pygame.KEYDOWN, {'unicode': '', 'key': 274, 'mod': 0, 'scancode': 108, 'test': True}))
    
barbazoo
  • 977
  • 5
  • 11