-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisable_led.py
44 lines (34 loc) · 1.42 KB
/
disable_led.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
from colorama import Fore, init
import sys
from os import name, system
# initializing colorama
init(autoreset=True)
def disable_rgb():
"""
Disables the Keyboard LED Backlight.
Return codes are:
0 when successed.
1 when raised a KeyboardInterrupt event, or when an Exception in the mainloop happens.
10 when running on Windows.
20 when not running on any compatible OS Type. (not windows, or mac, or linux)
"""
if name == 'posix': # if os is linux
try:
system('xset -led named "Scroll Lock"')
return 0
except Exception or KeyboardInterrupt:
print(f"{Fore.RED}[Exception] an Exception has occured that caused the program to terminate it's event loop")
return 1
elif name == 'nt': # if on windows.
print(f"{Fore.RED}[ERROR] Incompatible OS type for script file.")
print(f"{Fore.YELLOW}[INFO] The script file will close.")
return 10 # error code 10 is for incompatible OS type.
else: # if not either windows or linux (but not mac)
print(f"{Fore.RED}[ERROR] Incompatible OS type {name}")
print(f"{Fore.YELLOW}[INFO] The script file will close.")
return 20 # error code 20 is for incompatible OS Type (not windows).
if __name__ == '__main__':
ret_code = disable_rgb()
sys.exit(ret_code)
else: # if program was imported as a Python module.
raise ImportError("You can't import this.")