-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtrigger-hotkeys.ahk
More file actions
127 lines (95 loc) · 3.42 KB
/
trigger-hotkeys.ahk
File metadata and controls
127 lines (95 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#Requires AutoHotkey v2.0
; #SingleInstance Force ; is buggy, using Heartbeat mechanism instead
#SingleInstance Off
#UseHook True
ListLines(False)
; trigger_hotkey.ahk
/**
* @file trigger-hotkeys.ahk
* @description Captures global hotkeys (F10/F11) to control the STT service.
* Designed to run with high privileges via Task Scheduler to override system keys.
* https://www.autohotkey.com/docs/v2/Language.htm#comments
*
*/
; --- Configuration ---
heartbeat_start_File := "c:\tmp\heartbeat_trigger_hotkey_start.txt"
triggerFile := "c:\tmp\sl5_record.trigger"
activeWinTitleFile := "c:\tmp\activeWinTitle.txt"
; --- Main Script Body ---
myUniqueID := A_TickCount . "-" . Random(1000, 9999)
try {
fileHandle := FileOpen(heartbeat_start_File, "w")
fileHandle.Write(myUniqueID)
fileHandle.Close()
} catch as e {
MsgBox("FATAL: Could not write heartbeat file: " . e.Message, "Error", 16)
ExitApp
}
; --- Self-Check at Startup ---
Sleep(200) ; Give time for write operations
try {
if FileExist(heartbeat_start_File) {
lastUniqueID := Trim(FileRead(heartbeat_start_File))
if (lastUniqueID != myUniqueID) {
ExitApp ; Newer instance exists, I must exit.
}
}
} catch {
; Ignore errors here, loop will handle it
}
SetTimer(CheckHeartbeatStart, 5000)
; =============================================================================
; SELF-TERMINATION VIA HEARTBEAT CHECK
; =============================================================================
CheckHeartbeatStart() {
global heartbeat_start_File, myUniqueID
try {
local lastUniqueID := Trim(FileRead(heartbeat_start_File, "UTF-8"))
if (lastUniqueID != myUniqueID) {
; New instance took over
ExitApp
}
} catch {
; If file is locked/deleted, better safe than sorry -> exit
ExitApp
}
}
; =============================================================================
; HOTKEY DEFINITIONS (F10 & F11)
; =============================================================================
; Prevent Windows from capturing F10 and F11 input
; the '$' modifier to the F10 and F11 hotkey forces AutoHotkey to use the keyboard hook, preventing the native Windows events (like menu activation) from firing alongside the script.
*$f10::
$f11::
{
static lastPress := 0
if (A_TickCount - lastPress < 900) ; 500ms Sperre
return
lastPress := A_TickCount
activeWinTitle := WinGetTitle('A')
; MsgBox, "%activeWinTitle%"
local activeWinTitleFile := "c:\tmp\activeWinTitle.txt"
try FileDelete activeWinTitleFile
FileAppend activeWinTitle, activeWinTitleFile
if InStr(activeWinTitle, ".py - Notepad++")
{
Send("^s")
}
local TriggerFile := "c:\tmp\sl5_record.trigger"
FileAppend("t", TriggerFile)
ToolTip("STT Trigger ausgelöst!")
SetTimer(() => ToolTip(), -1500)
}
; ------------------------------------------------------------------
; STRG+Q -> CopyQ Window/Fenster toggle/umschalten (Anzeigen/Verstecken)
; ------------------------------------------------------------------
$^q::
{
; both should work show and toggle: https://github.com/hluk/CopyQ/issues/3011
; Standard-Pfad definieren
exePath := "C:\Program Files\CopyQ\copyq.exe"
; "C:\Program Files\CopyQ\copyq.exe" toggle
SplitPath exePath, &exeName, &exeDir
; Run('"' exePath '" toggle', exeDir)
Run('"' exePath '" show', exeDir)
}