1+ from contextlib import suppress
2+ from time import sleep
13from keyboard import press_and_release as hotkey
24from winregal import RegKey
5+ from os import system
6+
7+
8+ def _get_filter_info (value : str ):
9+ with suppress (FileNotFoundError ):
10+ with RegKey (r"HKEY_CURRENT_USER\Software\Microsoft\ColorFiltering" ) as key :
11+ return key .get_value (value ).data
312
413
514def is_active ():
6- with RegKey (r"HKEY_CURRENT_USER\Software\Microsoft\ColorFiltering" ) as key :
7- return bool (key .get_value ("Active" ).data )
15+ return bool (_get_filter_info ("Active" ))
16+
17+
18+ def is_hotkey_enabled ():
19+ return bool (_get_filter_info ("HotkeyEnabled" ))
20+
21+
22+ def get_filter_type ():
23+ return _get_filter_info ("FilterType" ) or 2 # Grayscale by default
824
925
1026def set_active (value ):
@@ -16,3 +32,31 @@ def toggle():
1632 hotkey ("ctrl+win" , do_release = False )
1733 hotkey (46 )
1834 hotkey ("ctrl+win" , do_press = False )
35+
36+
37+ def setup_color_filer_settings ():
38+ hotkey_enabled = is_hotkey_enabled ()
39+
40+ if hotkey_enabled and get_filter_type () == 1 :
41+ return
42+
43+ was_active = is_active ()
44+ system ("start ms-settings:easeofaccess-colorfilter" )
45+ sleep (1 )
46+ # Windows has bug, when opening easeofaccess-colorfilter
47+ # while this window is already opened
48+ # filter will always set to Gray
49+ # So you must check which filter selected twice :)
50+
51+ options = (was_active , hotkey_enabled , get_filter_type () == 1 )
52+ for skip_option in options :
53+ if not skip_option :
54+ hotkey ("Space" )
55+ hotkey ("Tab" )
56+
57+ if not was_active :
58+ for i in range (len (options )):
59+ hotkey ("Shift + Tab" )
60+ hotkey ("Space" )
61+
62+ hotkey ("Alt + F4" )
0 commit comments