0

i'm initiating to python code and I need help : How can I do a condition , if on the terminal , there is written like " {name} has said HEY " ? Like if someone say HEY ( if it came out of the terminal ) , how I can transform it to a condition ? Like " if HEY == on terminal "

  print("Someone has said say !!!")

( I want to do this but with true python , Idk how to do It)

Swyzax
  • 17
  • 3

1 Answers1

0

It looks like there is a similiar question answered at Looping until a specific key is pressed I modified the code in the one I linked to modify a variable each time a key is was pushed in a specific order. I didn't make it where it had to be consecutive but after "h","e",&"y" are type in that order, it will stop with a printed message. There are a lot of ways to do this but this was the easiest way to show you that it can be done.

import keyboard
import time
import threading

class main:
    def __init__(self):
        # Create a run variable
        self.run = True

        # Start main thread and the break thread
        self.mainThread = threading.Thread(target=self.main)
        self.breakThread = threading.Thread(target=self.breakThread)

        self.mainThread.start()
        self.breakThread.start()
    phrase = 'None'
    def breakThread(self):
        print('Break thread runs')
        # Check if run = True
        while True and self.run == True:
            if keyboard.is_pressed('h'):
                phrase = 'h'
            if keyboard.is_pressed('e') and (phrase=='h'):
                phrase = 'he'
            if keyboard.is_pressed('y') and (phrase=='he'):
                self.newFunction()
                phrase = 'None'
                break
          
    def main(self):
        print('Main thread runs')
  
    
        # Also check if run = True   
        while not keyboard.is_pressed('esc') and self.run == True:
            print('test')
            time.sleep(2)
        
            # Break like this
            if keyboard.is_pressed('esc'):
                break

            print('test')
            time.sleep(2)

    def newFunction(self):
        self.run = False
        print('Password accepted')
        print('You are in the new function!')

program = main()
Omnishroom
  • 253
  • 1
  • 8
  • It's like that , but I need to replace the if keyboard.is_pressed('esc'): by something like if terminal.print.HEY – Swyzax Sep 27 '22 at 17:04