1

I'm trying to add a reaction to arrow key. While I was trying to, I deciced to try just print the reaction when the key is pressed, as I found here. When I write anything to console terminal, nothing happens. I am using PyCharm. Q: How to make it print the value as it should print?

 import msvcrt
 while True:
    if msvcrt.kbhit():
       key = msvcrt.getch()
       print(key)
carolinesed
  • 57
  • 1
  • 8

1 Answers1

1

Edit : Under run configuration enable this - Emulate terminal in output console (see below)

enter image description here

Remove extra indentation

Error I get

File "run.py", line 2 while True: ^ IndentationError: unexpected indent

Code should be indented like this. Tested and it works.

import msvcrt
while True:
  if msvcrt.kbhit():
      key = msvcrt.getch()
      print(key)

enter image description here

Hassan Voyeau
  • 3,383
  • 4
  • 22
  • 24