Skip to content

Commit f425913

Browse files
committed
Refactor user config handling and update default hotkey to Ctrl+L
1 parent 1283142 commit f425913

5 files changed

Lines changed: 49 additions & 4 deletions

File tree

build.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ echo PawGate Build Script
77
echo ========================================
88
echo.
99

10+
REM Remove user config so builds always start from bundled defaults
11+
set "CONFIG_FILE=%USERPROFILE%\.pawgate\config\config.json"
12+
if exist "%CONFIG_FILE%" (
13+
del /f /q "%CONFIG_FILE%"
14+
echo Removed user config at %CONFIG_FILE%
15+
) else (
16+
echo No user config to remove at %CONFIG_FILE%
17+
)
18+
1019
REM Use venv if it exists, otherwise use system Python
1120
if exist ".venv\Scripts\python.exe" (
1221
set "PYTHON=.venv\Scripts\python.exe"

resources/config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "hotkey": "ctrl+b", "opacity": 0.3, "notificationsEnabled": false }
1+
{ "hotkey": "ctrl+l", "opacity": 0.3, "notificationsEnabled": false }

run_build.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
"""Run PyInstaller build for PawGate."""
2+
import os
23
import subprocess
34
import sys
4-
import os
5+
6+
from src.util.path_util import get_config_path
7+
8+
9+
def delete_user_config() -> None:
10+
"""Remove the user config file so each build starts clean."""
11+
config_path = get_config_path()
12+
if os.path.exists(config_path):
13+
os.remove(config_path)
14+
print(f"Removed user config: {config_path}")
15+
else:
16+
print(f"No user config found at: {config_path}")
17+
18+
19+
delete_user_config()
520

621
os.chdir(r'C:\github\pawgate')
722

src/config/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
BUNDLED_CONFIG_FILE = os.path.join("resources", "config", "config.json")
4545

4646
# Default hotkey if config is missing or invalid
47-
# WHY Ctrl+B: "B" stands for "Block", is easy to reach, and avoids common shortcuts
48-
DEFAULT_HOTKEY = "ctrl+b"
47+
# WHY Ctrl+L: Easy to reach, avoids common system shortcuts (unlike Win+L),
48+
# and maps well to "lock" in PawGate's context.
49+
DEFAULT_HOTKEY = "ctrl+l"
4950

5051

5152
def should_use_bundled_config():

src/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ def _get_hotkey_keys(self) -> list[str]:
220220
hotkey_keys.append(key)
221221
return hotkey_keys
222222

223+
def _get_hotkey_scan_codes(self) -> set[int]:
224+
"""Return the scan codes for the configured hotkey (including modifier variants)."""
225+
scan_codes: set[int] = set()
226+
for key_name in self._get_hotkey_keys():
227+
try:
228+
for code in keyboard.key_to_scan_codes(key_name):
229+
scan_codes.add(code)
230+
except Exception:
231+
# If keyboard cannot resolve a key name on this layout, skip it.
232+
continue
233+
return scan_codes
234+
223235
def lock_keyboard(self) -> None:
224236
"""
225237
Block ALL keyboard input using comprehensive scan code blocking.
@@ -258,9 +270,15 @@ def lock_keyboard(self) -> None:
258270
"""
259271
self.blocked_keys.clear()
260272

273+
# Determine scan codes used by the unlock hotkey so we do NOT block them.
274+
hotkey_scan_codes = self._get_hotkey_scan_codes()
275+
261276
# Block full scan code range (0-255) to cover all keyboards including
262277
# multimedia keys, F13-F24, and regional/international layouts
263278
for i in range(256):
279+
if i in hotkey_scan_codes:
280+
# Skip blocking the unlock hotkey scan codes so the hotkey still works.
281+
continue
264282
try:
265283
keyboard.block_key(i)
266284
self.blocked_keys.add(i)
@@ -273,6 +291,8 @@ def lock_keyboard(self) -> None:
273291
# Block extended scan codes that Windows uses for brightness/backlight controls.
274292
# These live outside the 0-255 range and need explicit handling.
275293
for extended_code in EXTENDED_SCAN_CODES:
294+
if extended_code in hotkey_scan_codes:
295+
continue
276296
try:
277297
keyboard.block_key(extended_code)
278298
self.blocked_keys.add(extended_code)

0 commit comments

Comments
 (0)