I have a simple python script, that has some functions that run in a loop (I'm taking sensor readings).
while True:
print "Doing a function"
If the keyboard is pressed I'd like to print "key pressed".
What's the simplest way of doing this in Python? I've searched high and low. I've found out how to do it with pygame, but I'd rather do it without. If I do have to use pygame is it possible to not have a separate window for the application?:
import pygame, time
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('Pygame Keyboard Test')
pygame.mouse.set_visible(0)
while True:
print "doing a function"
for event in pygame.event.get():
if (event.type == KEYUP) or (event.type == KEYDOWN):
print "key pressed"
time.sleep(0.1)
0 answers
Hot tools Tags
Hot Questions
Popular tool
vc9-vc14 (32+64 bit) runtime library collection (link below)
Download the collection of runtime libraries required for phpStudy installation
VC9 32-bit
VC9 32-bit phpstudy integrated installation environment runtime library
PHP programmer toolbox full version
Programmer Toolbox v1.0 PHP Integrated Environment
VC11 32-bit
VC11 32-bit phpstudy integrated installation environment runtime library
SublimeText3 Chinese version
Chinese version, very easy to use
Hot Topics
20519
7
13632
4






