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
Closed

How to add multiple keypress event listener ? #98

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

Comments

@wilon
Copy link
Collaborator

@wilon wilon 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
Copy link
Member

@vcaesar vcaesar 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.

Loading

@Mebus
Copy link

@Mebus Mebus commented Jan 31, 2018

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

Loading

@bonly
Copy link

@bonly bonly commented Feb 3, 2018

yes, me too, it is ahk style use

Loading

@vcaesar
Copy link
Member

@vcaesar vcaesar commented Feb 3, 2018

I will update it or give me a PR.

Loading

@wilon
Copy link
Collaborator Author

@wilon wilon 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.

Loading

@afdalwahyu
Copy link

@afdalwahyu afdalwahyu commented Feb 16, 2018

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

Loading

@vcaesar vcaesar added this to the v0.50.0 milestone Apr 28, 2018
@vcaesar vcaesar removed this from the v0.50.0 milestone Aug 8, 2018
@vcaesar vcaesar added this to the v0.60.0 milestone Aug 8, 2018
@JuicyASen
Copy link

@JuicyASen JuicyASen commented Sep 15, 2018

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

Loading

@vcaesar vcaesar removed this from the v0.60.0 milestone Oct 9, 2018
@vcaesar vcaesar added this to the v0.70.0 milestone Oct 9, 2018
@wbzqe
Copy link

@wbzqe wbzqe commented Dec 10, 2018

same issue here.. like 'ctrl+a'

Loading

@vcaesar vcaesar removed this from the v0.70.0 milestone Jan 7, 2019
@vcaesar vcaesar added this to the v0.80.0 milestone Jan 7, 2019
@vcaesar
Copy link
Member

@vcaesar vcaesar commented Feb 18, 2019

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

Loading

@vcaesar vcaesar closed this in 753e280 Feb 21, 2019
@vcaesar
Copy link
Member

@vcaesar vcaesar commented Mar 11, 2019

fmt.Println("--- Please press ctrl + shift + q ---")
ok := robotgo.AddEvents("q", "ctrl", "shift")
if ok {
	fmt.Println("add events...")
}

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants