]> Skullheadx's Git Forge - Typer-Noises.git/commitdiff
Clean up files + hard stop for typer and support of multiple copypastas
authorSkullheadx <704277@pdsb.net>
Fri, 30 Dec 2022 22:22:38 +0000 (17:22 -0500)
committerSkullheadx <704277@pdsb.net>
Fri, 30 Dec 2022 22:22:38 +0000 (17:22 -0500)
14 files changed:
copy-pastas/BeeMovieScript.txt [moved from BeeMovieScript.txt with 100% similarity]
copy-pastas/YoshikageKira.txt [moved from YoshikageKira.txt with 100% similarity]
copy-pastas/apologies.txt [moved from apologies.txt with 100% similarity]
copy-pastas/astleyparadox.txt [moved from astleyparadox.txt with 100% similarity]
copy-pastas/badjoke.txt [moved from badjoke.txt with 100% similarity]
copy-pastas/eatingpizza.txt [new file with mode: 0644]
copy-pastas/grammaticalerror.txt [moved from grammaticalerror.txt with 100% similarity]
copy-pastas/notcopypasta.txt [moved from notcopypasta.txt with 100% similarity]
copy-pastas/notgamer.txt [moved from notgamer.txt with 100% similarity]
copy-pastas/rickroll.txt [moved from rickroll.txt with 100% similarity]
main.py
reddit-admin-typing.mp3 [moved from reddit-admin-typing-14393.mp3 with 100% similarity]
test.txt [deleted file]
typer_game.py

similarity index 100%
rename from apologies.txt
rename to copy-pastas/apologies.txt
similarity index 100%
rename from badjoke.txt
rename to copy-pastas/badjoke.txt
diff --git a/copy-pastas/eatingpizza.txt b/copy-pastas/eatingpizza.txt
new file mode 100644 (file)
index 0000000..937c6eb
--- /dev/null
@@ -0,0 +1 @@
+So here I was enjoying my favorite food (pizza) and watching YouTube having a good time when it started to taste funny. It turns out you were being super salty and now have ruined my pizza. Are you going to pay for another pizza or will I have to call the cops? This is serious.
similarity index 100%
rename from notgamer.txt
rename to copy-pastas/notgamer.txt
similarity index 100%
rename from rickroll.txt
rename to copy-pastas/rickroll.txt
diff --git a/main.py b/main.py
index 8740948d068375c0d411c150129ddc30f7b9190c..0289f731153798652842dd9f0eb5a307d9b9ff7e 100644 (file)
--- a/main.py
+++ b/main.py
@@ -1,41 +1,56 @@
 import threading
 import time
+import os
 from pygame import mixer
 from pynput import keyboard
 
+TEXT_PATH = "copy-pastas/"
 
-with open("badjoke.txt", "r") as f:
-    script = f.read()
-    script = script.replace("’", "'")
+delay = 0.025  # delay between each character typed in seconds.
 
+keys = {eval(f"keyboard.Key.f{i + 1}"): "" for i in range(12)}
+scripts = []
+for root, dirs, files in os.walk(TEXT_PATH):
+    for i, x in enumerate(zip(files, keys)):
+        file, key = x
+        with open(os.path.join(TEXT_PATH, file), "r") as f:
+            keys[key] = f.read().replace("’", "'")
 
+# Sound
 mixer.init()
-
-mixer.music.load("reddit-admin-typing-14393.mp3")
+mixer.music.load("reddit-admin-typing.mp3")
 mixer.music.set_volume(0.5)
 
-delay = 0.025
+# to stop typing before end.
+stopped = False
+
 
-def typer():
+def typer(text):
+    global stopped
     mixer.music.play(-1)
     k = keyboard.Controller()
-    for char in script:
+    for char in text:
         if char == "\n":
             char = keyboard.Key.enter
-        # print(f"{char=}, {keyboard.Key.enter}", end='')
         k.press(char)
         time.sleep(delay)
         k.release(char)
+        if stopped:
+            break
     mixer.music.stop()
 
 
 def on_press(key):
-    if key == keyboard.Key.f5:
-        t = threading.Thread(target=typer)
+    global stopped
+    if key in keys:  # having another thread so we can detect input while typing
+        stopped = False
+        t = threading.Thread(target=typer, args=[keys[key]])
         t.start()
-    if key == keyboard.Key.esc:
+    elif key == keyboard.Key.pause:
+        stopped = True
+    elif key == keyboard.Key.esc:
         quit()
 
 
-with keyboard.Listener(on_press=on_press) as listener:
+with keyboard.Listener(on_press=on_press) as listener:  # listening for events
     listener.join()
diff --git a/test.txt b/test.txt
deleted file mode 100644 (file)
index d68dd40..0000000
--- a/test.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-a
-b
-c
-d
index 02db39650f9f02ac4ac38dfb49d1e88a3a7bb934..5fe493709d5c08ed8a7530f1cd9eccda74973717 100644 (file)
@@ -46,7 +46,7 @@ class Words:
         self.index = 0
         self.typed_words = [""]
         self.display_words = [self.font.render("", True, BLACK)]
-        self.position = pygame.Vector2(self.left_bound, HEIGHT/2)
+        self.position = pygame.Vector2(self.left_bound, HEIGHT / 2)
 
         self.draw_cursor = True
         self.time = 0
@@ -76,12 +76,12 @@ class Words:
             self.draw_cursor = not self.draw_cursor
             self.time = 0
         self.time += delta
+
     def add_new_line(self):
         self.position.y -= self.display_words[-1].get_height()
         self.typed_words.append("")
         self.display_words.append(self.font.render("", True, BLACK))
 
-
     def draw(self, surf):
         surf.fill(WHITE)
         prev = self.position.copy()
@@ -95,7 +95,9 @@ class Words:
         # pygame.draw.line(surf, BLACK, (self.left_bound, 0), (self.left_bound, HEIGHT))
         # pygame.draw.line(surf, BLACK, (self.right_bound, 0), (self.right_bound, HEIGHT))
         if self.draw_cursor:
-            pygame.draw.line(surf, BLACK, (prev.x + self.display_words[-1].get_width(),prev.y - self.display_words[-1].get_height()),(prev.x + self.display_words[-1].get_width(),prev.y))
+            pygame.draw.line(surf, BLACK, (
+                prev.x + self.display_words[-1].get_width(), prev.y - self.display_words[-1].get_height()),
+                             (prev.x + self.display_words[-1].get_width(), prev.y))
 
 
 game = Words()