-
Notifications
You must be signed in to change notification settings - Fork 0
/
MidiScreensaverKicker.py
executable file
·60 lines (48 loc) · 1.32 KB
/
MidiScreensaverKicker.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
#
# Kick the screensaver by sending a SimulateActivity via dbus
# when a midi event occur
#
# To use on ubuntu
# apt install python3-mido python3-dbus python3-rtmidi xdotool
#
# then manualy start (or add on autostart)
#
import time
import mido
import argparse
import subprocess
# Track last time we send the kick
last_send = time.time()
class ScreenSaverKick:
def __init__(self):
None
def Kick(self):
subprocess.run(["xdotool", "key", "ctrl"])
def get_msg(msg):
# On message receive: SimulateActivity
global last_send
print(msg)
t = time.time()
if (t - last_send) > 30:
last_send = t
print("ping")
saver_interface.Kick()
# Open dbus interface
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="verbose", action='store_true')
parser.add_argument("-s", "--simulate", help="simulate action on screensaver", action='store_true')
args = parser.parse_args()
saver_interface = ScreenSaverKick()
if args.simulate:
saver_interface.Kick()
else:
print("start")
# Add a callback on each midi input port
inports = mido.get_input_names()
for i in inports:
print("Connect to {}".format(i))
mido.open_input(i, callback=get_msg)
# Finaly wait forever...
while True:
time.sleep(3660)