Best practices AutoHotkey v2. Use when writing AHK v2 scripts - covers global variable declarations, SetTimer usage, event handlers, and GUI positioning.
Provides AutoHotkey v2 best practices for global variables, SetTimer usage, event handlers, and GUI positioning.
/plugin marketplace add theflysurfer/claude-skills-marketplace/plugin install theflysurfer-claude-skills-marketplace@theflysurfer/claude-skills-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
; INCORRECT - Cause erreur "variable not assigned"
SomeFunction() {
g_MyGlobalVar := "value" ; ERREUR!
}
; CORRECT - Déclaration explicite requise
SomeFunction() {
global g_MyGlobalVar ; OBLIGATOIRE
g_MyGlobalVar := "value" ; OK
}
FunctionUsingGlobals() {
; Déclarer TOUTES les variables globales utilisées
global g_AppVersion, g_IsInitialized, g_ConfigFile
global g_CachedPhrases, g_SavedSelections, g_CurrentProject
; Maintenant on peut les utiliser
g_IsInitialized := true
return g_AppVersion
}
; Module.ahv2 - Description du module
; Encodage : UTF-8 avec BOM
; AutoHotkey v2
; Variables globales du module (si nécessaire)
global g_ModuleVar := ""
; 1. Configuration TOUJOURS EN PREMIER
#Include "Config\Settings.ah2"
#Include "Config\Paths.ah2"
; 2. Modules Core
#Include "Core\Logger.ah2"
#Include "Core\FileManager.ah2"
; 3. Modules Features (qui dépendent de Core)
#Include "Features\PhraseManager.ah2"
; 4. GUI en dernier
#Include "GUI\MainInterface.ah2"
; INCORRECT - Timer() n'existe pas en AHK v2
g_TooltipTimer := Timer(GUI_TooltipCheckMouse, 100)
g_TooltipTimer.Start()
; CORRECT - Utiliser SetTimer
SetTimer(GUI_TooltipCheckMouse, 100)
; CORRECT - Arrêter timer
SetTimer(GUI_TooltipCheckMouse, 0) ; 0 = arrêter
; CORRECT - Timer périodique avec variable de contrôle
g_TimerActive := true
SetTimer(MyFunction, 100)
StopMyTimer() {
global g_TimerActive
g_TimerActive := false
SetTimer(MyFunction, 0)
}
; INCORRECT - Signature trop spécifique peut échouer
GUI_HandleResize(GuiObj, MinMax, Width, Height) {
; Cette signature peut ne pas correspondre à l'événement réel
}
; CORRECT - Signature flexible avec paramètres variables
GUI_HandleResize(*) {
; Récupérer dimensions via la GUI elle-même
global g_MainGui
g_MainGui.GetPos(, , &Width, &Height)
; ... traitement
}
; CORRECT - Event handlers standards
g_MainGui.OnEvent("Close", (*) => GUI_Hide())
g_MainGui.OnEvent("Size", GUI_HandleResize) ; Fonction sans parenthèses
g_MainGui.OnEvent("Escape", (*) => GUI_Hide())
; CORRECT - Signatures standard ListView
ListView_OnItemCheck(ListViewObj, Item, Checked) {
; Item = numéro ligne, Checked = true/false
}
ListView_OnItemFocus(ListViewObj, Item) {
; Item = numéro ligne qui a le focus
}
; CORRECT - Assignment
g_ListView.OnEvent("ItemCheck", ListView_OnItemCheck)
g_ListView.OnEvent("ItemFocus", ListView_OnItemFocus)
; PROBLÈME COURANT - Interface mal dimensionnée
CreateGUI() {
; Boutons positionnés trop bas, pas visibles
g_Button1 := g_Gui.Add("Button", "x10 y450 w80 h30", "OK")
g_ListView := g_Gui.Add("ListView", "x10 y70 w620 h400", cols)
; Total height = 70 + 400 + 30 = 500px mais fenêtre fait 480px
}
; SOLUTION - Calculs cohérents
CreateGUI() {
; Définir dimensions fenêtre d'abord
windowHeight := 450
headerHeight := 70
footerHeight := 80 ; boutons + marge
; ListView adaptatif
listViewHeight := windowHeight - headerHeight - footerHeight
g_ListView := g_Gui.Add("ListView", "x10 y" . headerHeight . " w620 h" . listViewHeight, cols)
; Boutons dans footer calculé
buttonY := headerHeight + listViewHeight + 10
g_Button1 := g_Gui.Add("Button", "x10 y" . buttonY . " w80 h30", "OK")
}
; STRUCTURE ENRICHIE POUR CACHE
Cache_LoadData() {
global g_CachedPhrases
currentTitleNumber := 0
currentPhraseNumber := 0
; Créer objets avec métadonnées complètes
for lineNum, currentLine in lines {
if (InStr(currentLine, ";;#") = 1) {
currentTitleNumber++
currentPhraseNumber := 0
titleText := Trim(SubStr(currentLine, 4))
g_CachedPhrases.Push({
Type: "Title",
Text: "[" . currentTitleNumber . "] === " . titleText . " ===",
OriginalText: titleText,
TitleNumber: currentTitleNumber
})
} else {
currentPhraseNumber++
g_CachedPhrases.Push({
Type: "Phrase",
Text: "[" . currentTitleNumber . "." . currentPhraseNumber . "] " . currentLine,
OriginalText: currentLine,
TitleNumber: currentTitleNumber,
PhraseNumber: currentPhraseNumber
})
}
}
}
GUI_ProcessPhrases() {
global g_CachedPhrases
for phraseObj in g_CachedPhrases {
; Vérification existence propriété
originalText := phraseObj.HasProp("OriginalText") ? phraseObj.OriginalText : phraseObj.Text
; Traitement conditionnel par type
if (phraseObj.Type = "Title") {
; Traitement spécial titres
} else if (phraseObj.Type = "Phrase") {
; Traitement phrases normales
}
}
}
; Variables globales
global g_AppVersion := "1.0.0"
global g_IsInitialized := false
global g_ConfigFile := ""
; Fonctions - Module_Action
Logger_Write()
Cache_Initialize()
PhraseManager_LoadData()
; Constantes en majuscules
global MAX_CACHE_SIZE := 1000
global DEFAULT_TIMEOUT := 5000
Avant de déployer un script AutoHotkey v2 :
global appropriées..\..\)This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.