1

Is it possible to get python to read a key (such as Enter or Escape or an Arrow Key) pressed by the user and to record the keycode of that key in a variable?

I looked at this Python key binding/capture but this only displays the character that you press in the shell. I want to record this value in a variable, no need to print it (and not the python '\n' for Enter but the real keycode (like 13 I think it is on Windows) for the Enter key).

Community
  • 1
  • 1
Yello Four
  • 227
  • 1
  • 4
  • 17

1 Answers1

0

This works for me. @MosheRabaev was right and this is just the code version. I guess you just have to find the characters for all the special keys (like the '\r' for Enter). No clue what the characters are for arrow keys though...

import wx
user_input = str(raw_input())

user_input += '\r' #If they press the Enter Key
print user_input

if ord(user_input) == wx.WXK_RETURN:
        print "hey"
print "what"
Yello Four
  • 227
  • 1
  • 4
  • 17