robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

How to disable system key & mouse's behavior, at the same time the hook event can be caught?

Open wilon opened this issue 5 years ago • 0 comments

  • Robotgo version (or commit ref): latest
  • Go version: 1.12.1
  • Provide example code:
package main

import (
	"fmt"
	"time"

	"github.com/go-vgo/robotgo"
	hook "github.com/robotn/gohook"
)

var eventsStorage []hook.Event

func main() {
	fmt.Println("Start...")

	// collect key events
	go keyListen()
	time.Sleep(time.Duration(10000) * time.Millisecond)

	// output regular
	for _, v := range eventsStorage {
		key := hook.RawcodetoKeychar(v.Rawcode)
		robotgo.KeyTap(key)
		time.Sleep(time.Duration(333) * time.Millisecond)
	}
}

func keyListen() {
	s := hook.Start()
	defer hook.End()
	for ev := range s {
		if ev.Rawcode >= 0 && ev.Kind == hook.KeyUp {
			eventsStorage = append(eventsStorage, ev)
		}
	}
}

  • run:

Run this file, then key press 'asdfg', wait and regular output 'asdfg'. I want regular output 'asdfg' only, Key press behavior don't output.

Description

How to disable system key & mouse's behavior, at the same time the hook event can be caught? I want to storage the event and then do something.

wilon avatar May 15 '19 09:05 wilon