인터넷을 통해 잠시 동안 찾고 있었지만 리눅스 및 Windows 용 화살표를 잡을 수있는 독특한 방법을 찾지 못하는 것 같습니다.(Python3) Linux 및 Windows 화살표 키 누르기
from msvcrt import getch
while True:
print ('Distance from zero: ' + str(pos))
key = ord(getch())
if key == 224: #Special keys (arrows, f keys, ins, del, etc.)
key = ord(getch())
if key == 80: #Down arrow
Linux의 경우 나는 termios
패키지 사용 :
import sys,tty,termios
class _Getch:
def __call__(self):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(3)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def get():
inkey = _Getch()
while(1):
k=inkey()
if k!='':break
if k=='\x1b[A':
print ("up")
def main():
for i in range(0,20):
get()
if __name__=='__main__':
main()
가 나는 또한 리눅스와 윈도우에서 지원하는 패키지를 찾았을 창에 msvcrt
패키지와
내가이 솔루션을 발견 : keyboard
import keyboard #Using module keyboard
while True:#making a loop
try: #used try so that if user pressed other than the given key error will not be shown
if keyboard.is_pressed(keyboard.KEY_DOWN):#if arrow down is pressed
print('You Pressed down Key!')
이 se ems는 Windows에서는 좋지만 Linux에서는 작동하지 않습니다.
은 (내가 스택 오버 플로우에 대한 모든 구현을 발견했다.)내 목표는 다른 선택에 위아래로 내 화살표를 이동하는 것입니다. 이 작업을 완료하는 다른 방법도 환영합니다.