Skip to content

Commit df5d41c

Browse files
committed
Setup filter options at startup
1 parent 056ac63 commit df5d41c

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

active_window_checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ def __init__(self):
216216

217217
def setup(self):
218218
self.rules.on_rules_changed = self.update_filter_state
219+
color_filter.setup_color_filer_settings()
219220

220221
async def run(self):
221222
await to_thread(

color_filter.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
from contextlib import suppress
2+
from time import sleep
13
from keyboard import press_and_release as hotkey
24
from 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

514
def 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

1026
def 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

Comments
 (0)