Advertisement
MeckeOfficial

DLDU Counter

Oct 21st, 2021
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. import pip
  2. try:
  3.     from pynput import keyboard
  4. except ImportError:
  5.     pip.main(['install', pynput])
  6.     from pynput import keyboard  
  7. import subprocess
  8. import os
  9.  
  10. # Steuerung:
  11.  
  12. # Numpad 7
  13. # + 5 Punkte
  14.  
  15. # Numpad 4
  16. # - 5 Punkte
  17.  
  18. # Numpad 9
  19. # + 3 Punkte
  20.  
  21. # Numpad 6
  22. # - 3 Punkte
  23.  
  24. # If Points File does not exist, create a new one
  25. if not os.path.exists("./points.txt"):
  26.     with open("./points.txt", "w") as f:
  27.         f.write("0")
  28.  
  29. # Adds or Removes 5 Points depending on which Key is pressed
  30. def boss(sign="+"):
  31.  
  32.     with open("./points.txt", "r") as f:
  33.         points = int(f.readline())
  34.    
  35.     if sign == "+":
  36.         points += 5
  37.         print(f'''+ 5 Punkte
  38.        Neuer Stand: {points} Punkte.
  39.        ''')
  40.     else:
  41.         points -= 5
  42.         print(f'''- 5 Punkte
  43.        Neuer Stand: {points} Punkte.
  44.        ''')
  45.  
  46.     if points < 0:
  47.         points = 0
  48.  
  49.     with open("./points.txt", "w") as f:
  50.         f.write(str(points))
  51.  
  52. # Adds or Removes 3 Points depending on which Key is pressed
  53. def miniboss(sign="+"):
  54.    
  55.     with open("./points.txt", "r") as f:
  56.         points = int(f.readline())
  57.    
  58.     if sign == "+":
  59.         points += 3
  60.         print(f'''+ 3 Punkte
  61.        Neuer Stand: {points} Punkte.
  62.        ''')
  63.     else:
  64.         points -= 3
  65.         print(f'''- 3 Punkte
  66.    Neuer Stand: {points} Punkte.
  67.    ''')
  68.  
  69.     if points < 0:
  70.         points = 0
  71.  
  72.     with open("./points.txt", "w") as f:
  73.         f.write(str(points))
  74.  
  75. # checks every Key that is pressed
  76. def on_press(key):
  77.  
  78.     try:
  79.  
  80.         # 103 is NumPad 7       - adds 5 Points
  81.         if key.vk == 103:
  82.             boss()
  83.  
  84.         # 100 is NumPad 4       - removes 5 Points
  85.         if key.vk == 100:
  86.             boss("-")
  87.  
  88.         # 105 is NumPad 9       - adds 3 Points
  89.         if key.vk == 105:
  90.             miniboss()
  91.  
  92.         # 102 is NumPad 6       - aremoves 3 Points
  93.         if key.vk == 102:
  94.             miniboss("-")
  95.  
  96.     # if there are any Errors, we just ignore it
  97.     except:
  98.         pass
  99.  
  100. # Little Motivation
  101. print("Auf geht's, viel Erfolg!")
  102.  
  103. # Infinite Loop to check pressed Keys
  104. while True:
  105.     with keyboard.Listener(on_press=on_press) as listener:
  106.         listener.join()
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement