Reputation: 11
In Pascal I can execute this code to get a character from keyboard input:
uses crt;
var ch: char;
begin
ch := '.';
while ch <> '\' do
begin
ch := readkey;
writeln( ch );
end;
end;
Is there a similar one in Python? :)
Upvotes: 1
Views: 4440
Reputation: 339
import sys
def prog():
char = ""
while char != "/":
char = sys.stdin.read(1)
print char
prog()
Upvotes: 3
Reputation: 1386
You could do it by running Tkinter
in the background:
import Tkinter
def keyPress(event, tk):
ch = event.char
if ch == '\\':
tk.destroy()
else:
print ch
if __name__ == '__main__':
tk = Tkinter.Tk()
tk.bind_all('<Key>', lambda event: keyPress(event, tk))
tk.withdraw()
tk.mainloop()
(Hacked from: http://www.daniweb.com/forums/post567365.html#post567365)
Upvotes: 2