본문 바로가기
파이썬

파이썬에서 "키를 누르는"방법은 무엇입니까?

by º기록 2021. 2. 1.
반응형

파이썬에서 "키 누르기"(또는 메뉴 옵션 가져 오기)를 수행하려면 어떻게해야합니까?

표준 라이브러리를 사용하여이를 수행 할 수있는 휴대용 방법이 있습니까?

 

해결 방법

 

try:
    # Win32
    from msvcrt import getch
except ImportError:
    # UNIX
    def getch():
        import sys, tty, termios
        fd = sys.stdin.fileno()
        old = termios.tcgetattr(fd)
        try:
            tty.setraw(fd)
            return sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old)

 

참조 페이지 https://stackoverflow.com/questions/1394956

 

 

반응형

댓글