Created
June 29, 2017 03:10
-
-
Save moutend/7cbb741c7e2506b2fd840a3843839bc4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// +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