1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| #!/usr/bin/env python
#-*- coding: utf-8 -*-
#
#
import threading
import sys
class SetAffichage(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self._stopevent = threading.Event()
self._getch=_Getch()
def run(self):
while not self._stopevent.isSet():
_lettre = self._getch()
if _lettre == 'a':
self.stop()
print _lettre
def stop(self):
self._stopevent.set()
class _Getch:
def __init__(self):
if sys.platform == 'linux2':
self.getch = _GetchUnix()
elif sys.platform == 'win32':
self.getch = _GetchWindows()
elif sys.platform == 'darwin':
self.getch = _GetchMac()
else:
pass # TODO
def __call__(self):
return self.getch()
class _GetchUnix:
def __init__(self):
import tty
def __call__(self):
import tty, termios
_fd = sys.stdin.fileno()
_old_settings = termios.tcgetattr(_fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(_fd, termios.TCSADRAIN, _old_settings)
return ch
class _GetchWindows:
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
class _GetchMac:
def __init__(self):
import Carbon
def __call__(self):
import Carbon
# A finir
if Carbon.Evt.EventAvail(0x0008)[0]==0:
return ''
else:
(what, msg, when, where, mod)=Carbon.Evt.GetNextEvent(0x0008)
return chr(msg & 0x000000FF)
trhvar = SetAffichage()
trhvar.start() |
Partager