Skip to content

Instantly share code, notes, and snippets.

@paprikka
Last active October 10, 2024 13:34
Show Gist options
  • Save paprikka/da7e5ed94fb6c02716473fe2a574b0dd to your computer and use it in GitHub Desktop.
Save paprikka/da7e5ed94fb6c02716473fe2a574b0dd to your computer and use it in GitHub Desktop.
from pynput import keyboard
import time
import os
cmd_pressed = False
copy_count = 0
def on_press(key):
global cmd_pressed, copy_count
try:
if key == keyboard.Key.cmd:
cmd_pressed = True
elif cmd_pressed and key.char in ['c', 'v']:
copy_count += 1
print(f"CMD+C detected. Total count: {copy_count}")
if copy_count % 10 == 0: # Write to file every 10 copy/paste actions
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
with open(os.path.expanduser('~/how-many-times-did-I-press-CMD-C-or-V.gregg'), 'a') as f:
f.write(f"{timestamp}: CMD+C/V pressed {copy_count} times\n")
except AttributeError:
pass
def on_release(key):
global cmd_pressed
if key == keyboard.Key.cmd:
cmd_pressed = False
with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment