Skip to content

Instantly share code, notes, and snippets.

@moutend
Created June 29, 2017 03:10
Show Gist options
  • Save moutend/7cbb741c7e2506b2fd840a3843839bc4 to your computer and use it in GitHub Desktop.
Save moutend/7cbb741c7e2506b2fd840a3843839bc4 to your computer and use it in GitHub Desktop.
// +build windows
package main
import (
"fmt"
"log"
"os"
"syscall"
"time"
"github.com/moutend/winhook"
)
var count int
func add(code, wParam, lParam uint32) uintptr {
fmt.Println("called", count, code, wParam, lParam)
count++
return winhook.CallNextHookEx(0, code, wParam, lParam)
}
func main() {
var err error
if err = run(os.Args); err != nil {
log.Fatal(err)
}
fmt.Println("done")
return
}
func run(args []string) (err error) {
fmt.Println("@@@")
fn := syscall.NewCallback(add)
lr := winhook.SetWindowsHookExW(winhook.WH_KEYBOARD_LL, fn, 0, 0)
if lr != 0 {
fmt.Println("unknown error %v", lr)
}
fmt.Println("sleeping")
var r bool
var msg *winhook.MSG
for n := 0; n < 10; n++ {
r = winhook.GetMessageW(&msg, 0, 0, 0)
fmt.Println("received ", r, n)
}
time.Sleep(20 * time.Second)
fmt.Println("done")
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment