I have created a Python script that can take commands from a pipe (named pipe1). You can find the Script on Pastebin.
I tested the script with this other script:
import sys
fw = open("pipe1", "w" )
fw.write('fd\n')
fw.close()
and it worked.
Now I want to control the script with another Python script, that could write in the pipe if I press w, a, s, d or p and display me the keys, that i press.
In this example I just want to print the keys that I press. I would later add the fw.write commands to write in the pipe, which I tested before:
def key_inp(event):
print 'Key:', event.char
key_press = event.char
sleep_time = 0.030
while True:
try:
if key_press.lower() == 'w':
print "w"
elif key_press.lower() == 's':
print "s"
elif key_press.lower() == 'a':
print "a"
elif key_press.lower() == 'd':
print "d"
elif key_press.lower() == 'q':
print "q"
elif key_press.lower() == 'e':
print "e"
elif key_press.lower() == 'p':
print "stop"
except(KeyboardInterrupt):
print('Finished')
My problem is, that the script that i wrote (and improved with a stackoverflow member) closes immediately when i open it.
Can anyone explain me why, and how i can fix it so that the script stays open the whole time until i interrupt it with Ctrl+c?
key_presscomes from?..Is it the same in thewhileloop and the inkey_inpfunction?