| File was renamed from VoiceSnapGo/internal/hotkey/hotkey_darwin.go |
| | |
| | | if (g_activityToken != nil) return; |
| | | g_activityToken = [[NSProcessInfo processInfo] |
| | | beginActivityWithOptions:NSActivityUserInitiatedAllowingIdleSystemSleep |
| | | reason:@"VoiceSnap global hotkey listener"]; |
| | | reason:@"PrivateVoice Input global hotkey listener"]; |
| | | } |
| | | |
| | | static void* eventTapThreadMain(void* arg) { |
| | |
| | | static int isSideModifierDown(int keyCode) { |
| | | if (keyCode >= 0 && keyCode < 128) { |
| | | if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, (CGKeyCode)keyCode)) return 1; |
| | | if (g_keysDown[keyCode] && g_lastDownAt[keyCode] > 0 && nowSeconds() - g_lastDownAt[keyCode] < 0.25) return 1; |
| | | if (g_keysDown[keyCode]) g_keysDown[keyCode] = 0; |
| | | if (g_lastDownAt[keyCode] > 0 && nowSeconds() - g_lastDownAt[keyCode] < 0.12) return 1; |
| | | unsigned long long mask = modifierMaskForKey((unsigned short)keyCode); |
| | | int modifierDown = mask != 0 ? isModifierDown(mask) : 0; |
| | | double age = g_lastDownAt[keyCode] > 0 ? nowSeconds() - g_lastDownAt[keyCode] : 999.0; |
| | | if (g_keysDown[keyCode]) { |
| | | if (modifierDown) return 1; |
| | | if (age < 0.25) return 1; |
| | | g_keysDown[keyCode] = 0; |
| | | return 0; |
| | | } |
| | | if (age < 0.12) return 1; |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | C.beginHotkeyActivity() |
| | | trusted := C.ensureAccessibility() |
| | | if trusted == 0 { |
| | | logger.Info("Accessibility permission not granted for current app identity — hotkey won't work until VoiceSnap is removed and re-added in System Settings > Privacy & Security > Accessibility") |
| | | logger.Info("Accessibility permission not granted for current app identity — hotkey won't work until PrivateVoice Input is removed and re-added in System Settings > Privacy & Security > Accessibility") |
| | | } else { |
| | | logger.Info("Accessibility permission granted") |
| | | } |