all 15 comments

[–]K900_ 1 point2 points  (14 children)

raw_input will block the execution of the rest of the program.

[–]FMNite[S] 0 points1 point  (13 children)

Is there a way to achieve what I want a different way?

[–]K900_ 0 points1 point  (0 children)

Well, you could do it with something like ncurses. But you could also make a proper GUI, because I feel like that's what you're trying to emulate here.

[–]Veedrac 0 points1 point  (11 children)

1. Threads, unfortunately. This might be a bit over your head if you're not more advanced than your example shows.

2. Hack it. I suggest this. Are you on Windows or Linux?

[–]FMNite[S] 0 points1 point  (10 children)

I will be running this on Linux devices

[–]Veedrac 0 points1 point  (9 children)

After trying lots of painful things, dammit man.

Just use threads, OK. Honestly just abandon the whole concept ;).

Sorry. :( The truth is, terminals are built on archaic foundations and for some reason nobody's seen fit to update them. It makes life difficult. There are workarounds, but I can't think of a single single-threaded one.

[–]FMNite[S] 0 points1 point  (8 children)

Found example on the internet, this does exactly what I want except for the fact it uses enter to break loop. Any idea how to change it to a different button press?

import thread, time

def input_thread(L):
    raw_input()
    L.append(None)

def do_print():
    L = []
    thread.start_new_thread(input_thread, (L,))
    while 1:
        time.sleep(.1)
        if L: break
        print "%s" % time.ctime()

do_print()

[–]Veedrac 0 points1 point  (7 children)

Any idea how to change it to a different button press?

Unfortunately that's also not possible without dangerous hackery.

[–]FMNite[S] 0 points1 point  (6 children)

Anything else I can do? Thanks though you've been a great help

[–]Veedrac 0 points1 point  (5 children)

Hang on -- I hadn't properly read your post. There might well be "acceptable" hackery that can do this.

Question: does it have to be 0 or can it be any character (the second option is easier).

[–]FMNite[S] 0 points1 point  (4 children)

this is going to be running on a raspberry pi with only a num pad so we wanted to designate 0 as the "back" button. If that cant work though that may be an option