New keyboard shortcuts

This commit is contained in:
Muzhen Gaming
2025-10-16 10:23:45 +08:00
parent 5901254405
commit d9fc7d4b61
5 changed files with 68 additions and 31 deletions

View File

@@ -5,12 +5,12 @@ from dataclasses import dataclass
@dataclass
class Settings:
# Hotkeys (Windows format for `keyboard` lib)
shortcut_capture: str = "alt+shift+1"
shortcut_send: str = "alt+shift+2"
shortcut_action3: str = "alt+shift+3"
shortcut_reset: str = "alt+shift+4"
shortcut_quit: str = "alt+shift+5"
shortcut_toggle_mode: str = "alt+shift+6"
shortcut_capture: str = "ctrl+shift+1"
shortcut_send: str = "ctrl+shift+2"
shortcut_action3: str = "ctrl+shift+3"
shortcut_reset: str = "ctrl+shift+4"
shortcut_quit: str = "ctrl+shift+5"
shortcut_toggle_mode: str = "ctrl+shift+6"
# OpenAI
model: str = "Google Gemini_2.5"
@@ -35,6 +35,29 @@ class Settings:
captures_dir_name: str = "captures"
response_file_name: str = "response.txt"
log_file_name: str = "agent.log"
suppress_hotkeys: bool = True
def __post_init__(self):
# Allow hotkey overrides via environment variables for easy customization
# Example: set BG_AGENT_SHORTCUT_SEND="ctrl+shift+enter"
env_map = {
"BG_AGENT_SHORTCUT_CAPTURE": "shortcut_capture",
"BG_AGENT_SHORTCUT_SEND": "shortcut_send",
"BG_AGENT_SHORTCUT_ACTION3": "shortcut_action3",
"BG_AGENT_SHORTCUT_RESET": "shortcut_reset",
"BG_AGENT_SHORTCUT_QUIT": "shortcut_quit",
"BG_AGENT_SHORTCUT_TOGGLE_MODE": "shortcut_toggle_mode",
}
for env, attr in env_map.items():
val = os.environ.get(env)
if val:
setattr(self, attr, val)
# Optional: allow disabling suppression via env
sup = os.environ.get("BG_AGENT_SUPPRESS_HOTKEYS")
if sup is not None:
v = str(sup).strip().lower()
self.suppress_hotkeys = v in {"1", "true", "yes", "on"}
def ensure_dirs(cfg: Settings) -> None: