Пример #1
0
func main() {
	var err error

	defer cleanup()

	keyboards, err = evdev.Find(evdev.Keyboard)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Find keyboards: %v\n", err)
		return
	}

	mice, err = evdev.Find(evdev.Mouse)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Find mice: %v\n", err)
		return
	}

	fmt.Printf("Keyboards: %d\n", len(keyboards))
	for _, dev := range keyboards {
		fmt.Printf(" - %s at %s\n", dev.Name(), dev.Path())
	}

	fmt.Printf("Mice: %d\n", len(keyboards))
	for _, dev := range mice {
		fmt.Printf(" - %s at %s\n", dev.Name(), dev.Path())
	}

	if len(keyboards) == 0 || len(mice) == 0 {
		return
	}

	// Poll for events or exit signals.
	signals := make(chan os.Signal, 1)
	signal.Notify(signals, os.Kill, os.Interrupt)
	for {
		select {
		case <-signals:
			return

		case evt := <-keyboards[0].Inbox:
			fmt.Printf("Keyboard: %v\n", evt)

		case evt := <-mice[0].Inbox:
			fmt.Printf("Mouse: %v\n", evt)
		}
	}
}
Пример #2
0
func findKeyboard(t *testing.T) *evdev.Device {
	keyboards, err := evdev.Find(evdev.Keyboard)
	if err != nil {
		t.Fatal(err)
	}

	if len(keyboards) == 0 {
		t.Fatal("No keyboards found")
	}

	kb := keyboards[0]

	// Close remaining keyboards. We do not need them.
	for _, dev := range keyboards[1:] {
		dev.Close()
	}

	return kb
}