keylogger icon indicating copy to clipboard operation
keylogger copied to clipboard

I use two keyboards (laptop and USB connected), one works, the other doesn't. Why?

Open leabit opened this issue 1 year ago • 2 comments

My code:

package main

import (
	"fmt"

	"github.com/MarinX/keylogger"
)

func main() {
        // k, err := keylogger.New("/dev/input/event14")
	k, err := keylogger.New("/dev/input/event3")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer k.Close()

	events := k.Read()

	for e := range events {
		switch e.Type {
		case keylogger.EvKey:
			if e.KeyPress() {
				fmt.Println("[event] press key ", e.KeyString())
			}
		}
	}
}

I have two keyboards. One original from the laptop (/dev/input/event3) and one connected to laptop via USB (/dev/input/event14). When I use keylogger.New("/dev/input/event3") and press something on the laptop keyboard everything works as I expect. However, when I change to keylogger.New("/dev/input/event14"), that is, to my other keyboard and press something on that keyboard, nothing happens.

The result of sudo lsinput:


....

/dev/input/event3
   bustype : BUS_I8042
   vendor  : 0x1
   product : 0x1
   version : 43962
   name    : "AT Translated Set 2 keyboard"
   phys    : "isa0060/serio0/input0"
   bits ev : (null) (null) (null) (null) (null)

....

/dev/input/event14
   bustype : BUS_USB
   vendor  : 0x258a
   product : 0x3a
   version : 273
   name    : "SINO WEALTH Gaming KB  Keyboard"
   phys    : "usb-0000:04:00.3-2.3/input1"
   uniq    : ""
   bits ev : (null) (null) (null) (null)

....

Why is this happening? What should I do?

leabit avatar Apr 13 '24 12:04 leabit

@MarinX any progress?

leabit avatar Sep 14 '24 00:09 leabit

@leabit Try below and see if it works:

package main

import (
	"fmt"
	"log"

	"github.com/MarinX/keylogger"
)

func main() {

	keyboards := keylogger.FindAllKeyboardDevices()

	for index, keyboard := range keyboards {
		go func() {
			k, err := keylogger.New(keyboard)

			if err != nil {
				log.Printf("Error: %s\n", err)
				return
			}

			for e := range k.Read() {
				switch e.Type {
				case keylogger.EvKey:
					if e.KeyPress() {
						fmt.Printf("[event] press key from %d: %s\n", index, e.KeyString())
					}
				}
			}
		}()
	}

	select {}
}

starfreck avatar Jan 23 '25 08:01 starfreck