From d811123166ac1fa9d583960d9b682bbd64d0ef03 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Fri, 24 Apr 2020 22:45:27 +0200 Subject: [PATCH] Allowing the user to exit the app by pressing escape --- main.py | 43 +++++++++++++++++++++++++++++++++++++------ packages.txt | 2 ++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 packages.txt diff --git a/main.py b/main.py index 63a170e..53f4a5f 100755 --- a/main.py +++ b/main.py @@ -1,13 +1,44 @@ #!/usr/bin/env python3 -import os import time +import pyxhook from term_utils import TermUtils from command_helper import CommandHelper -TermUtils.print("YOU HAVE BEEN HACKED.\n") -while True: - if CommandHelper.run("killall htop") == 0 or CommandHelper.run("killall top") == 0: - TermUtils.print("You tough that this will be as easy as this?\n") - time.sleep(1) +class AnonymousGoose: + def __init__(self): + self.should_exit = False + self.stopped = False + self.tricks = [] + self.keyboard_listener = pyxhook.HookManager() + self.keyboard_listener.KeyUp = self.key_pressed + self.keyboard_listener.HookKeyboard() + self.keyboard_listener.start() + TermUtils.print("YOU HAVE BEEN HACKED.\n") + self.run() + + def __del__(self): + if not self.stopped: + self.keyboard_listener.cancel() + + def run(self): + while not self.should_exit: + if CommandHelper.run("killall htop") == 0 or CommandHelper.run("killall top") == 0: + TermUtils.print("You tough that this will be as easy as this?\n") + time.sleep(1) + + def key_pressed(self, key): + if key.Ascii == 27: + self.should_exit = True + + def stop(self): + if self.stopped: + return + self.keyboard_listener.cancel() + self.stopped = True + + +if __name__ == "__main__": + goose = AnonymousGoose() + goose.stop() diff --git a/packages.txt b/packages.txt new file mode 100644 index 0000000..c0f8f91 --- /dev/null +++ b/packages.txt @@ -0,0 +1,2 @@ + +pyxhook \ No newline at end of file