How to use the getch.getche function in getch

To help you get started, we’ve selected a few getch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanjeethboddi / DiscoSnake / game.py View on Github external
def main():
    init(autoreset=True)
    os.system('cls' if os.name == 'nt' else 'clear')
    print("\t \t Snake")
    print("==============")
    print("W - to move up")
    print("S - to move down")
    print("A - to move left")
    print("D - to move right")
    print("==============")
    while True:
            print('press Y to Start the game and N to exit:  ',end="")
            x = getch.getche()
            print("")
            if x== 'Y' or x=='N' or x=='y' or x=='n':
                break
            else:
                print("wrong input try again")
    if x=='n' or x=='N':
        sys.exit()
    game_over = multiprocessing.Value('i')
    game_over.value = 0
    direction = multiprocessing.Value('i')
    direction.value=ord('D')
    moved = multiprocessing.Value('i')
    moved.Value=0
    lock = multiprocessing.Lock()
    process1=multiprocessing.Process(target=dir_input,args=(direction,game_over,lock,moved))
    process2=multiprocessing.Process(target=game_start,args=(direction,game_over,lock,moved))
github RafaelBroseghini / Pythonista / Random-Problems / raceXandZ.py View on Github external
def race(distance):
    inp = getch.getche()
    correct = MOVES["x"]
    distance_ran = 0
    if inp == correct:
        distance_ran += 1
        start = time.time()
        while distance_ran < distance:
            correct = MOVES[correct]
            while inp != correct:
                inp = getch.getche()
            else:
                distance_ran += 1
        end = time.time()
        return "\nFinished in: {:.3f}s".format(end-start)
    return "\nYou burned the lead!\n"
github RafaelBroseghini / Pythonista / Random-Problems / raceXandZ.py View on Github external
def race(distance):
    inp = getch.getche()
    correct = MOVES["x"]
    distance_ran = 0
    if inp == correct:
        distance_ran += 1
        start = time.time()
        while distance_ran < distance:
            correct = MOVES[correct]
            while inp != correct:
                inp = getch.getche()
            else:
                distance_ran += 1
        end = time.time()
        return "\nFinished in: {:.3f}s".format(end-start)
    return "\nYou burned the lead!\n"

getch

Does single char input, like C getch/getche

Public-Domain
Latest version published 11 years ago

Package Health Score

43 / 100
Full package analysis