11# Requires AutoHotkey v2.0
2+ #SingleInstance Force
23
3- ; ============================================================================
4- ; AHK_Common.ahk - Common utility functions for AutoHotkey scripts
5- ; Version: 2.0.0 (Migrated to AHK v2)
6- ; ============================================================================
4+ ; AHK_Common – shared init utilities
75
8- ; ============================================================================
9- ; InitUIA() - No longer needed in AHK v2
10- ; UIA (UI Automation) support is built-in to AutoHotkey v2
11- ; This function is kept for compatibility but does nothing
12- ; ============================================================================
136InitUIA () {
14- ; UIA is built-in to AHK v2 - no action needed
15- return
7+ ; UIA is built-in in v2 (no-op, kept for compatibility)
168}
179
18- ; ============================================================================
19- ; RequireAdmin() - Ensures script runs with administrator privileges
20- ; Relaunches script with admin rights if not already running as admin
21- ; ============================================================================
2210RequireAdmin () {
23- if ( ! A_IsAdmin ) {
24- try {
25- Run (' * RunAs " ' . A_ScriptFullPath . ' " ')
26- ExitApp ( )
27- } catch Error as err {
28- MsgBox ( " Failed to elevate to admin: " . err.Message)
29- ExitApp ( )
30- }
11+ if A_IsAdmin
12+ return
13+ try {
14+ Run (' * RunAs " ' . A_ScriptFullPath . ' " ' )
15+ ExitApp ()
16+ } catch Error as err {
17+ MsgBox ( " Failed to elevate: " . err.Message )
18+ ExitApp ()
3119 }
3220}
3321
34- ; ============================================================================
35- ; SetOptimalPerformance() - Applies performance optimization settings
36- ; Disables delays for maximum script execution speed
37- ; Note: Some v1 directives are deprecated/removed in v2
38- ; ============================================================================
3922SetOptimalPerformance () {
40- ; Note: #KeyHistory and ListLines are deprecated in v2
41- ; These are now controlled by script directives only
4223 SetKeyDelay (- 1 , - 1 )
4324 SetMouseDelay (- 1 )
4425 SetDefaultMouseSpeed (0 )
@@ -47,23 +28,11 @@ SetOptimalPerformance() {
4728 SendMode (" Input" )
4829}
4930
50- ; ============================================================================
51- ; InitScript(requireUIA := true, requireAdmin := false, optimize := true)
52- ; Convenience function to initialize script with common settings
53- ;
54- ; Parameters:
55- ; requireUIA - Run with UIA support (default: true) - No-op in v2
56- ; requireAdmin - Run with admin privileges (default: false)
57- ; optimize - Apply performance optimizations (default: true)
58- ; ============================================================================
5931InitScript (requireUIA := true, requireAdmin := false, optimize := true ) {
60- ; UIA is built-in to v2, so InitUIA() does nothing
61- if (requireUIA)
32+ if requireUIA
6233 InitUIA()
63-
64- if (requireAdmin)
34+ if requireAdmin
6535 RequireAdmin()
66-
67- if (optimize)
36+ if optimize
6837 SetOptimalPerformance()
6938}
0 commit comments