How to determine input devices?

interpretive language scripts


Moderator: Forum moderators

Post Reply
HerrBert
Posts: 359
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 128 times

How to determine input devices?

Post by HerrBert »

Hello.

I have a question about input detection in Puppy Linux

All i ever found on detecting user input idle time used in Puppy Linux is getcurpos.
Works as suggested, no question.
Problem is when it comes to keyboard input or scrollwheel activity.
This is always annoying when reading long text using the scrollwheel or up/down-keys on my keyboard.

A solution might be a script found at https://crunchbang.org/forums/viewtopic.php?id=26447, which uses /proc/interrupts.

But as always there is a glitch in this script...
How do you determine the correct device in /proc/interrupts?

On my Laptop i can grep i8042 as mentioned in script. But on my Desktop i8042 is present but doesn't change on mouse or keyboard activity.
On my Desktop i found keyboard and mouse activity on uhci_hcd:usb5
Maybe i'm the lucky one with keyboard and mouse on the same bus...

Question is, how to determine input devices via (bash-) script on startup?

some1
Posts: 86
Joined: Wed Aug 19, 2020 4:32 am
Has thanked: 18 times
Been thanked: 15 times

Re: determine input devices

Post by some1 »

What about /var/log/messages - probably around line 1000 +/- 200.

step
Posts: 550
Joined: Thu Aug 13, 2020 9:55 am
Has thanked: 58 times
Been thanked: 198 times
Contact:

Re: How to determine input devices?

Post by step »

evtest, if installed (likely so), should be enough to test for input activity.
evtest by itself lists and describes input devices, which answers your question, I guess.

Monitoring input devices with evtest is also possible but needs a bit of shell code.
evtest /dev/input/eventX monitors activity of device X indefinitely -- you need to kill evtest to stop monitoring.
One could combine several devices with ( evtest /dev/input/eventX & /dev/input/eventY & ... ) and pipe that into a control structure that decides what to do when activity is detected. Sketchy, untested code follows:

Code: Select all

(
	evtest /dev/inputX &
	evtest /dev/inputY &
	...
) | while read line; do
	case $line in
		*"the event to which I'm paying attention"* )
			# do something sensible... then
			killall evtest
			break # out of this loop
		;;
	esac
done
HerrBert
Posts: 359
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 18 times
Been thanked: 128 times

Re: How to determine input devices?

Post by HerrBert »

My first attempt was ls -l /dev/input/by-path and grep mouse and kbd to get event# and then readlink of event# in /sys/class/input. Works only on 2 of 3 machines. So not reliable...

Gave /var/log/messages a try.
I was able to grep -E -i 'keyboard as|mouse as|touchpad as'¹ from my default keyboard and mouse and another wireless touchpad keyboard, which is also detected as mouse. But adding another wireless mouse detection failed due to device naming. In the latter case device identifies as 'Telink Wireless Receiver', so no match on keyboard|mouse|touchpad with grep.

¹) Depending on kernel i get different output for Keyboard...

Code: Select all

# grep -E -i 'keyboard|mouse|touchpad' /var/log/messages 
Feb 20 21:52:55 OptiPlex kern.info kernel: mousedev: PS/2 mouse device common for all mice
Feb 20 21:52:55 OptiPlex kern.info kernel: usb 5-1: Product: USB Keyboard
Feb 20 21:52:55 OptiPlex kern.info kernel: input:   USB Keyboard as /devices/pci0000:00/0000:00:1a.2/usb5/5-1/5-1:1.0/0003:1241:1503.0001/input/input5
Feb 20 21:52:55 OptiPlex kern.info kernel: hid-generic 0003:1241:1503.0001: input,hidraw0: USB HID v1.10 Keyboard [  USB Keyboard] on usb-0000:00:1a.2-1/input0
Feb 20 21:52:55 OptiPlex kern.info kernel: input:   USB Keyboard System Control as /devices/pci0000:00/0000:00:1a.2/usb5/5-1/5-1:1.1/0003:1241:1503.0002/input/input6
Feb 20 21:52:55 OptiPlex kern.info kernel: input:   USB Keyboard Consumer Control as /devices/pci0000:00/0000:00:1a.2/usb5/5-1/5-1:1.1/0003:1241:1503.0002/input/input7
Feb 20 21:52:55 OptiPlex kern.info kernel: hid-generic 0003:1241:1503.0002: input,hidraw1: USB HID v1.10 Device [  USB Keyboard] on usb-0000:00:1a.2-1/input1
Feb 20 21:52:55 OptiPlex kern.info kernel: usb 5-2: Product: USB Optical Mouse
Feb 20 21:52:55 OptiPlex kern.info kernel: input: USB Optical Mouse as /devices/pci0000:00/0000:00:1a.2/usb5/5-2/5-2:1.0/0003:1BCF:0005.0003/input/input8
Feb 20 21:52:55 OptiPlex kern.info kernel: hid-generic 0003:1BCF:0005.0003: input,hidraw2: USB HID v1.10 Mouse [USB Optical Mouse] on usb-0000:00:1a.2-2/input0
# 

BTW and maybe OT: what's different between USB Keyboard, USB Keyboard System Control and USB Keyboard Consumer Control?

No luck with evtest. Seems like slackware based Puppies don't have evtest. lsinput also not in (my) Puppy.

Most promising was to search for mouse and keyboard in /sys/devices/ with find.
Mouse is found by -name 'mouse*' but keyboard doesn't match. So i tried searching for -name '*numlock' with success.

From these results i am able to determine whether it's pci<la/lala>/usb (and bus) or platform/i8042.

Another problem with the afore mentioned script is that if your hardware has less usb busses, the more devices share the same interrupt (ex: my desktop has 8 busses with max. 2 devices on one bus, my laptop has 2 busses with 6 devices on bus 1 (without usb keyboard attached)). So detection of idle time may get inaccurate.

Post Reply

Return to “Scripts”