def run (self): while (1): c = Getch.getch() self.kbdready = True if c == chr(0x05): # ^E self.processor.reset = True if c == chr(0x03): # ^C print("Exiting") sys.exit() self.charQueue.put_nowait(self.toApple1(c))
def pull(): getch=Getch._Getch(); pin=libport.Port(3, libport.Port.IN); pout=libport.Port(5, libport.Port.OUT); k='0'; while (not k=='q'): k=getch(); if (k=='o'): pout.write(1); elif (k=='f'): pout.write(0); v=pin.read(); print "la tension est de {0} v :".format((v*3.3));
def controleKey(): global i; global k; getch=Getch._Getch(); while (not k=='c'): k=getch(); if (k=='q'):# and i>-0.5): i=i-0.1; elif (k=='d'): #and i<0.35): i=i+0.1; elif (k=='s'): i=0; print((Tc+i)*(10**(-3)), " ms");
def dealWithIt(match, para, replacementFunction): """ Deals with a pattern match. Checks for replacement, displays it for user and asks what to do with it""" replacement = suggestReplacement(match, para, replacementFunction) while True: print 'Suggested replacement:', replacement print '(a)ccept suggestion | (i)gnore:', option = gc.getch() print option if option == 'a': return replacement, True elif option == 'i': # elif option == 'e': # print "code to edit and write own correction here" # return getReplacement(match, para) print 'ignored... ' return para, False else: print 'invalid choice'
def controle(): i=0; k='0'; getch=Getch._Getch(); p22=libport.Port(7, libport.Port.OUT); #pext=libport.ExtPort(7, 0x20, libport.ExtPort.OUT); servo=libservo.Servo(p22); #servo=libservo.Servo(pext); servo.start(); while (not k=='c'): k=getch(); if (k=='d'): i=i-1; elif (k=='q'): i=i+1; elif (k=='s'): i=0; print ("{0}° ".format(i)); try: print servo._Tc+servo.rotate(i); except Exception: print "Error"; servo.stop();
"Demo the use of the _Getch class" import Getch getch = Getch._Getch() while 1: print "Enter keystroke (or ESC to escape):" char = getch() esc = '\x1b' if char == esc: break print char
] GameOver = [ ' _____ _____ ', '| __ \ | _ | ', '| | \/ __ _ _ __ ___ ___ | | | |_ _____ _ __ ', '| | __ / _` | \'_ ` _ \ / _ \ | | | \ \ / / _ \ \'__|', '| |_\ \ (_| | | | | | | __/ \ \_/ /\ V / __/ | ', ' \____/\__,_|_| |_| |_|\___| \___/ \_/ \___|_| ' ] ''' Initialization of Board, Bomberman, a global object that has its instance and Enemies ''' getch = Getch._Getch() Global.init() board = Board.Board() bomber = Bomberman.Bomber() Global.bomberwoman = bomber for i in range(Global.level + 5): Global.enemies.append(Enemy.Enemy()) Global.enemies[i].SetPosition(Global.enemyset[i][0], Global.enemyset[i][1]) ''' Taking single character input using getch ''' def static_input(): try: text = getch() except:
KEY_LEFT = "h" KEY_RIGHT = "l" KEY_P_1_UP = "w" KEY_P_1_DOWN = "s" KEY_P_1_LEFT = "a" KEY_P_1_RIGHT = "d" KEY_P_2_UP = "W" KEY_P_2_DOWN = "S" KEY_P_2_LEFT = "A" KEY_P_2_RIGHT = "D" portalColors = [123, 100, 255] Getch.start() while True: levelPath = "Levels/level" + str(levelNum) + ".lvl" if not os.path.isfile(levelPath): # We have finished the last level. break level = [list(x[:-1]) for x in open(levelPath, "r").readlines()] helpLine = "" exitMsg = "" i = 0 while i < len(level): line = "".join(level[i]) contain = True if line.startswith("Help:"): helpLine = line[5:].strip() contain = False if line.startswith("Exit:"):
def __init__(self): self.map = [[self.startWall(j, i) for i in range(20)] for j in range(10)] self.pos = Pos(5, 5) self.getch = g._Getch() self.hp = 9