Files
promptkey/lib/HotkeyManager.ahk
Spark b102a4a206 feat(core): moteur PromptKey — bibliothèque .md, variables, injection, raccourcis
- PromptStore/Frontmatter : un prompt = un fichier Markdown, en-tête au
  sous-ensemble strict du document d'architecture (§7), écriture UTF-8
- VariableEngine : variables typées + automatiques (selection, clipboard,
  date, app, cursor), résolution et profils de destination
- Injector/ClipboardGuard : focus capturé/rendu, presse-papiers sauvegardé
  puis restauré conditionnellement, aucun envoi automatique par défaut
- Search : classement flou insensible aux accents, pondéré par l'usage
- UsageStats (usage.json), HotkeyManager (conflits signalés, jamais muets)
- Settings : config.ini + profils par IA (claude, chatgpt, qwen, terminal…)
- PromptKey.ahk : tray, instance unique, capture du contexte, surveillance
  de la bibliothèque, installation du pack au premier lancement
2026-10-11 10:17:30 -04:00

73 lines
2.8 KiB
AutoHotkey

; HotkeyManager.ahk — Enregistrement des raccourcis globaux et hotstrings (architecture §13).
; Aucun conflit silencieux : tout échec est consigné dans this.Conflicts et signalé (§13.3).
class HotkeyManager {
Registered := [] ; raccourcis effectivement enregistrés (pour désactivation propre)
HotstringsOn := [] ; hotstrings effectivement activées
Conflicts := [] ; [ "description — erreur" ]
__New() {
}
Clear() {
for hk in this.Registered {
try Hotkey(hk, "Off")
}
for hs in this.HotstringsOn {
try Hotstring(hs, "Off")
}
this.Registered := []
this.HotstringsOn := []
this.Conflicts := []
}
; callbacks : Map { picker, manager, newPrompt, replay, usePrompt (Func(id, ...)) } — usePrompt reçoit l'id en premier (Bind).
RegisterAll(settings, prompts, callbacks) {
this.Clear()
this.TryHotkey(settings.PickerHotkey, callbacks["picker"], "Raccourci principal (Picker)")
this.TryHotkey(settings.ManagerHotkey, callbacks["manager"], "Raccourci Gestionnaire")
this.TryHotkey(settings.NewHotkey, callbacks["newPrompt"], "Raccourci Nouveau prompt")
this.TryHotkey(settings.ReplayHotkey, callbacks["replay"], "Raccourci Rejouer le dernier")
; Épinglés : Ctrl+Alt+1..9 (§13.1). Bind fige l'id (les fermetures AHK capturent par référence).
pinnedMap := Map()
for p in prompts {
if (p.Pinned >= 1 && p.Pinned <= 9)
pinnedMap[p.Pinned] := p.Id
}
for n, id in pinnedMap {
this.TryHotkey("^!" n, callbacks["usePrompt"].Bind(id), "Épinglé n° " n)
}
; Raccourcis propres et hotstrings par prompt.
for p in prompts {
if (p.Hotkey != "")
this.TryHotkey(p.Hotkey, callbacks["usePrompt"].Bind(p.Id), "Raccourci du prompt « " p.Title " »")
if (p.Hotstring != "") {
hs := "::" p.Hotstring
try {
Hotstring(hs, callbacks["usePrompt"].Bind(p.Id))
this.HotstringsOn.Push(hs)
} catch as e {
this.Conflicts.Push("Hotstring " hs " (« " p.Title " ») — " e.Message)
}
}
}
if (this.Conflicts.Length > 0) {
Util.Log("Conflits de raccourcis : " this.Conflicts.Length)
TrayTip(this.Conflicts.Length " raccourci(s) en conflit. Détail dans Paramètres.", "PromptKey — conflits de raccourcis")
}
}
TryHotkey(hk, callback, label) {
if (hk = "")
return
try {
Hotkey(hk, callback)
this.Registered.Push(hk)
} catch as e {
this.Conflicts.Push(label " (" hk ") — " e.Message)
}
}
}