Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pip
- try:
- from pynput import keyboard
- except ImportError:
- pip.main(['install', pynput])
- from pynput import keyboard
- import subprocess
- import os
- # Steuerung:
- # Numpad 7
- # + 5 Punkte
- # Numpad 4
- # - 5 Punkte
- # Numpad 9
- # + 3 Punkte
- # Numpad 6
- # - 3 Punkte
- # If Points File does not exist, create a new one
- if not os.path.exists("./points.txt"):
- with open("./points.txt", "w") as f:
- f.write("0")
- # Adds or Removes 5 Points depending on which Key is pressed
- def boss(sign="+"):
- with open("./points.txt", "r") as f:
- points = int(f.readline())
- if sign == "+":
- points += 5
- print(f'''+ 5 Punkte
- Neuer Stand: {points} Punkte.
- ''')
- else:
- points -= 5
- print(f'''- 5 Punkte
- Neuer Stand: {points} Punkte.
- ''')
- if points < 0:
- points = 0
- with open("./points.txt", "w") as f:
- f.write(str(points))
- # Adds or Removes 3 Points depending on which Key is pressed
- def miniboss(sign="+"):
- with open("./points.txt", "r") as f:
- points = int(f.readline())
- if sign == "+":
- points += 3
- print(f'''+ 3 Punkte
- Neuer Stand: {points} Punkte.
- ''')
- else:
- points -= 3
- print(f'''- 3 Punkte
- Neuer Stand: {points} Punkte.
- ''')
- if points < 0:
- points = 0
- with open("./points.txt", "w") as f:
- f.write(str(points))
- # checks every Key that is pressed
- def on_press(key):
- try:
- # 103 is NumPad 7 - adds 5 Points
- if key.vk == 103:
- boss()
- # 100 is NumPad 4 - removes 5 Points
- if key.vk == 100:
- boss("-")
- # 105 is NumPad 9 - adds 3 Points
- if key.vk == 105:
- miniboss()
- # 102 is NumPad 6 - aremoves 3 Points
- if key.vk == 102:
- miniboss("-")
- # if there are any Errors, we just ignore it
- except:
- pass
- # Little Motivation
- print("Auf geht's, viel Erfolg!")
- # Infinite Loop to check pressed Keys
- while True:
- with keyboard.Listener(on_press=on_press) as listener:
- listener.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement