keyboard control

This commit is contained in:
Foufure13
2024-12-09 23:40:07 +01:00
parent c02a08c41d
commit 096c605213
10 changed files with 97 additions and 139 deletions
+61 -41
View File
@@ -75,45 +75,70 @@ def print_help():
hprint("PURPLE", "Touche l : liste toute les génération")
hprint("PURPLE", "Touche m : change le prompt a donner a l'ia")
def start_keyboard_listener():
global listening_keyboard # Déclare que tu utilises la variable globale
listening_keyboard = True # Initialisation de la variable globale
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
def stop_keyboard_listener():
global listening_keyboard # Utilisation de la variable globale
listening_keyboard = False # Changer la valeur de la variable globale
# D'autres opérations pour arrêter le listener si nécessaire
def on_press(key):
global listening_keyboard
try:
if key.char == 'h':
if key == keyboard.Key.f5:
hprint("yellow", "Touche 'F5'BOT Active l'écoute clavier")
listening_keyboard = True
elif key == keyboard.Key.f6:
hprint("yellow", "Touche 'F6'BOT Désactive l'écoute clavier")
listening_keyboard = False
elif key.char == 'h':
hprint("cyan", "Touche 'h' détectée. Help")
print_help()
elif key.char == 'q': # Si la touche 'q' est pressée, arrête l'écoute
hprint("cyan", "Touche 'q' détectée. Fin du programme.")
main_loop = False
stop_all()
return False # Cela arrêtera l'écouteur
elif key.char == 'c':
hprint("cyan", "Touche 'c' clear terminal")
clear_screen()
elif key.char == 'u':
hprint("cyan", "Touche 'u' détectée. Arrêt de l'enregistrement.")
recordTw.stop() # Arrêter l'enregistrement
elif key.char == 'p':
hprint("cyan", "Touche 'p' détectée. Arrêt de la traduction en text.")
sb_translation.stop() # Arrêter l'enregistrement
elif key.char == 'k':
hprint("cyan", "Touche 'k' imagination réponse")
generation_responce()
elif key.char == 's':
hprint("cyan", "Touche 's' Envoie du message")
Message_text = ask_text.getlast_generation()
#send_message(tw_acc_pseudo, tw_acc_token, args.twitchname, Message_text)
elif key.char == 'o':
hprint("cyan", "Touche 'o'liste sous titre")
sb_translation.print_allsubtitle()
elif key.char == 'l':
hprint("cyan", "Touche 'l' liste génération")
ask_text.print_allgeneration()
elif key.char == 'x':
hprint("cyan", "Touche 'x' reload json")
ask_text.reload_json()
sb_translation.reload_json()
elif key.char == 'm':
hprint("cyan", "Touche 'm' change prompt ia")
ask_text.change_prompt()
if listening_keyboard:
if key.char == 'q': # Si la touche 'q' est pressée, arrête l'écoute
hprint("cyan", "Touche 'q' détectée. Fin du programme.")
main_loop = False
stop_all()
return False # Cela arrêtera l'écouteur
elif key.char == 'c':
hprint("cyan", "Touche 'c' clear terminal")
clear_screen()
elif key.char == 'u':
hprint("cyan", "Touche 'u' détectée. Arrêt de l'enregistrement.")
recordTw.stop() # Arrêter l'enregistrement
elif key.char == 'p':
hprint("cyan", "Touche 'p' détectée. Arrêt de la traduction en text.")
sb_translation.stop() # Arrêter l'enregistrement
elif key.char == 'k':
hprint("cyan", "Touche 'k' imagination réponse")
generation_responce()
elif key.char == 's':
hprint("cyan", "Touche 's' Envoie du message")
Message_text = ask_text.getlast_generation()
#send_message(tw_acc_pseudo, tw_acc_token, args.twitchname, Message_text)
elif key.char == 'o':
hprint("cyan", "Touche 'o'liste sous titre")
sb_translation.print_allsubtitle()
elif key.char == 'l':
hprint("cyan", "Touche 'l' liste génération")
ask_text.print_allgeneration()
elif key.char == 'x':
hprint("cyan", "Touche 'x' reload json")
ask_text.reload_json()
sb_translation.reload_json()
elif key.char == 'm':
hprint("cyan", "Touche 'm' change prompt ia")
ask_text.change_prompt()
except AttributeError:
pass
@@ -123,11 +148,6 @@ def generation_responce():
hprint("blue", "start IA_generator")
ask_text.main_ask(text_streamer)
def start_keyboard_listener():
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
#----------------------------------------------------------------------------------------------------
@@ -152,7 +172,7 @@ if __name__ == '__main__':
recordTw = RecordTwitch(channel_name=args.twitchname, recordtime=args.recordtime)
recordTw.start_recording()
hprint("blue", "start loop Subtitle_translation")
hprint("blue", "start loop Subtitle_translation")
sb_translation = Subtitle_translation("../config/config.json")
sb_translation.start_main_loop()