From 59466be3fc3121452ca290cb928feac4e5458532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 20 May 2024 22:05:24 +0300 Subject: [PATCH] d --- v4/main.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/v4/main.py b/v4/main.py index e0bdfd2..88aa5de 100644 --- a/v4/main.py +++ b/v4/main.py @@ -43,6 +43,9 @@ ctrl.registerCallback(printOutput) #c = shell_launch(c) #print(c.output) # + +ctrl.set("didLaunch", True) + #for line in sys.stdin: # c.input = line.rstrip() # c = shell_processInput(c) @@ -50,4 +53,36 @@ ctrl.registerCallback(printOutput) # break # print(c.output) -ctrl.set("didLaunch", True) + + + + + +import threading +import time + +class KeyboardThread(threading.Thread): + + def __init__(self, input_cbk = None, name='keyboard-input-thread'): + self.input_cbk = input_cbk + super(KeyboardThread, self).__init__(name=name, daemon=True) + self.start() + + def run(self): + while True: + self.input_cbk(input()) #waits to get input + Return + +showcounter = 0 #something to demonstrate the change + +def my_callback(inp): + #evaluate the keyboard input + print('You Entered:', inp, ' Counter is at:', showcounter) + +#start the Keyboard thread +kthread = KeyboardThread(my_callback) + +while True: + #the normal program executes without blocking. here just counting up + showcounter += 1 + time.sleep(0.5) +