Skip to content

Instantly share code, notes, and snippets.

@starkayc
Created April 11, 2025 01:07
Show Gist options
  • Select an option

  • Save starkayc/7ac76e5d2196b7680c9341487045098e to your computer and use it in GitHub Desktop.

Select an option

Save starkayc/7ac76e5d2196b7680c9341487045098e to your computer and use it in GitHub Desktop.
Score Counter with configurable keybinds
from pynput import keyboard
import os
# === CONFIGURABLE SECTION ===
file_path = "score.txt" # Change to your preferred path
left_key = 'a' # Key to increase the first number
right_key = 'd' # Key to increase the second number
reset_key = 'r' # Optional: reset to 0-0
exit_key = 'esc' # Optional: exit the script
# ============================
def read_score():
if not os.path.exists(file_path):
return 0, 0
with open(file_path, "r") as f:
content = f.read().strip()
try:
left, right = map(int, content.split('-'))
return left, right
except:
return 0, 0
def write_score(left, right):
with open(file_path, "w") as f:
f.write(f"{left}-{right}")
print(f"Updated score: {left}-{right}")
def on_press(key):
try:
k = key.char.lower()
except AttributeError:
if key == keyboard.Key.esc and exit_key == 'esc':
print("Exiting...")
return False
return
left, right = read_score()
if k == left_key:
left += 1
write_score(left, right)
elif k == right_key:
right += 1
write_score(left, right)
elif k == reset_key:
write_score(0, 0)
print(f"Listening for keypresses: [{left_key}] left +1, [{right_key}] right +1, [{reset_key}] reset, [Esc] to exit")
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
@echo off
setlocal
echo === Checking Python Installation ===
where python >nul 2>&1
IF %ERRORLEVEL% NEQ 0 (
echo [!] Python is not installed or not in PATH.
echo Please install Python from https://www.python.org/downloads/ and try again.
pause
exit /b
)
echo === Ensuring pip is installed ===
python -m ensurepip --default-pip
echo === Upgrading pip ===
python -m pip install --upgrade pip
echo === Installing pynput ===
python -m pip install pynput
echo.
echo === Done! 'pynput' is now installed ===
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment