Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add multiple keypress event listener ? #98

Closed
wilon opened this issue Jan 5, 2018 · 10 comments

Comments

Projects
None yet
7 participants
@wilon
Copy link
Contributor

commented Jan 5, 2018

I want press k do something, and press s do something.

I try it like this, but failed.

package main

import (
	"fmt"

	"github.com/go-vgo/robotgo"
)

func main() {

	kCh := make(chan int)
	go func() {
		for {
			fmt.Println("...event k")
			kCh <- robotgo.AddEvent("k")
		}
	}()

	sCh := make(chan int)
	go func() {
		for {
			fmt.Println("...event s")
			sCh <- robotgo.AddEvent("s")
		}
	}()

	for {
		switch {
		case <-kCh == 0:
			fmt.Println("you press...", "k")
		case <-sCh == 0:
			fmt.Println("you press...", "s")
		}
		fmt.Println("for switch")
	}
}
@vcaesar

This comment has been minimized.

Copy link
Member

commented Jan 6, 2018

I will test it and think about how to do it, and I'll fix it if there is a problem.

@Mebus

This comment has been minimized.

Copy link

commented Jan 31, 2018

I want something similar, but with left and right mouse button.

@bonly

This comment has been minimized.

Copy link

commented Feb 3, 2018

yes, me too, it is ahk style use

@vcaesar

This comment has been minimized.

Copy link
Member

commented Feb 3, 2018

I will update it or give me a PR.

@wilon

This comment has been minimized.

Copy link
Contributor Author

commented Feb 4, 2018

I'm sorry, I'm incapable for write C.

The func robotgo.AddEvent("v") is lock the system key listen.
https://github.com/go-vgo/robotgo/blob/master/event/goEvent.h#L69

https://github.com/go-vgo/robotgo/blob/master/event/goEvent.h#L152
I suggest to add func ——

string key_listener() {}        // C: goEvent.h, return the keypress string
func keyListener() string {}    // Go: robotgo.go

Then I can use it like this:

for {
	switch robotgo.keyListener() {
	case "k":
		fmt.Println("--- You press v---", "v")
	case "v":
		fmt.Println("--- You press k---", "k")
	case "mleft":
		fmt.Println("--- You click mouse---", "mleft")
	}
}

I hope it will help you.

@afdalwahyu

This comment has been minimized.

Copy link

commented Feb 16, 2018

hi @wilon i have the same problem too,
for someone still having same problem maybe this package could help

@vcaesar vcaesar added this to the v0.50.0 milestone Apr 28, 2018

@vcaesar vcaesar added the enhancement label Apr 28, 2018

@vcaesar vcaesar modified the milestones: v0.50.0, v0.60.0 Aug 8, 2018

@JuicyASen

This comment has been minimized.

Copy link

commented Sep 15, 2018

same issue here, and it will be very nice to have a keyDown/Up listener.

@vcaesar vcaesar modified the milestones: v0.60.0, v0.70.0 Oct 9, 2018

@wbzqe

This comment has been minimized.

Copy link

commented Dec 10, 2018

same issue here.. like 'ctrl+a'

@vcaesar vcaesar modified the milestones: v0.70.0, v0.80.0 Jan 7, 2019

@vcaesar

This comment has been minimized.

Copy link
Member

commented Feb 18, 2019

The code will be tested further and will be submitted within a week.

@vcaesar vcaesar closed this in 753e280 Feb 21, 2019

@vcaesar

This comment has been minimized.

Copy link
Member

commented Mar 11, 2019

fmt.Println("--- Please press ctrl + shift + q ---")
ok := robotgo.AddEvents("q", "ctrl", "shift")
if ok {
	fmt.Println("add events...")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.