Created
October 3, 2017 14:58
-
-
Save koenbollen/77fabe5f1cd0ad6ba158149d1619eca6 to your computer and use it in GitHub Desktop.
PoC global hotkey for OSX (using RegisterEventHotKey from the Carbon framework)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo LDFLAGS: -framework Carbon | |
// #include <Carbon/Carbon.h> | |
// extern void Callback(); | |
// void RunApplicationEventLoop(); | |
// static inline OSStatus handler(EventHandlerCallRef nextHandler, EventRef theEvent, void* userData) | |
// { | |
// Callback(); | |
// return 1; | |
// } | |
// static inline int Register(int key) { | |
// EventTypeSpec eventType; | |
// eventType.eventClass = kEventClassKeyboard; | |
// eventType.eventKind = kEventHotKeyPressed; | |
// | |
// InstallApplicationEventHandler(&handler, 1, &eventType, NULL, NULL); | |
// | |
// EventHotKeyID g_HotKeyID; | |
// g_HotKeyID.id = 1; | |
// | |
// EventHotKeyRef g_HotKeyRef; | |
// | |
// RegisterEventHotKey(key, 0, g_HotKeyID, GetApplicationEventTarget(), 0, &g_HotKeyRef); | |
// | |
// return 0; | |
// } | |
// static inline void Run() { | |
// RunApplicationEventLoop(); | |
// } | |
import "C" | |
import "fmt" | |
//export Callback | |
func Callback() { | |
fmt.Println("key pressed!") | |
} | |
func main() { | |
C.Register(C.kVK_F12) | |
C.Run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment