1

I need to capture keyboard events in Python2.7 on a raspberry pi. The simplest solution appears to be to use pygame, and I have this working successfully. However I am not writing a game and have no interest in displaying a blank 'window'. But this appears to be a necessity in order to use pygame's keyboard event handling functions. Is there a way not to have to display the window? My code snippet:

import pygame
import sys
pygame.display.init()
size = width, height = 320,240
#The line below creates the window and appears to be essential. Can I get around it?
screen = pygame.display.set_mode(size)
while 1:
    events=pygame.event.get()
    for event in events:
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                do something

Thank you

MartinC
  • 11
  • 2

0 Answers0