문제

Using Python and C (or just Python) how can I receive every pressed key from the keyboard while my program is running and output to the screen other key? For example, if user inputs 'F' it outputs 'ph'.

Thank you

도움이 되었습니까?

해결책

You can use msvcrt.getch() to get the key, and then map that to a value in a dictionary:

from msvcrt import getch

chars = {b'f': 'ph'}  # You could easily extend this dictionary.

while True:
    z = getch()
    if z in chars:
        print(chars[z])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top