-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.py
41 lines (32 loc) · 1.01 KB
/
key.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pynput.keyboard import Key, Listener
from codingame import CustomCodinGameClient
from dotenv import load_dotenv
import os
import time
# Load environment variables from .env file
load_dotenv()
# Access environment variables
ID = os.environ.get('ID')
COOKIE = os.environ.get('COOKIE')
# Initialize the Client
client = CustomCodinGameClient(ID, COOKIE)
# Handle the key press
## When the key is pressed
def on_press(key):
print('{0} pressed'.format(key))
## When the key is released
def on_release(key):
print('{0} release'.format(key))
if str(key) == "Key.shift_r": # Execute the code when clicked on RShift
print("Executing the code.")
client.exec()
if str(key) == "Key.ctrl_r": # Execute the code when clicked on RShift
print("Executing the code. [FORCED]")
client.exec(force=True)
if str(key) == "Key.f7":
return False
## Collect events until released
with Listener(
on_press=on_press,
on_release=on_release) as listener:
listener.join()