본문 바로가기
프로그램

[파이썬] 키보드 입력 감지

by 오디세이99 2022. 9. 6.
728x90
반응형

키보드 입력한 Key에 따라 동작하는 코드

import keyboard

def a_fun():
    for i in range(100):
        print('a!!! (',i,')')

def s_fun():
    for i in range(100):
        print('s!!! (',i,')')

while True:
    print('a : run(a), s : run(s), q : quit ==> key raady !!!')
    if keyboard.read_key() == 'q':
        print("quit(q)")
        break
    elif keyboard.read_key() == 'a':
        a_fun()
    elif keyboard.read_key() == 's':
        s_fun()
728x90
반응형

댓글