I want to detect when the user presses the RETURN/ENTER key. Right now, I am doing this using a while loop, but that blocks my code unless the while is broken.
Is there any way to detect the ENTER press without using while loops? I can't use tkinter either.
Your question is a little bit ambiguous (as noted by @TankorSmash). But here goes...
from multiprocessing import Process, Pipe
def f(c2):
count = 1
while not c2.poll():
print('hit ENTER to stop ({})'.format(count))
count += 1
c1, c2 = Pipe()
p = Process(target=f, args=(c2,))
p.start()
raw_input()
c1.send(None)
p.join()
My answer still uses while, but it doesn't block the running code. Does this work for you?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With