How can i detect presence of USB keyboard from user space program ?

Nov 08, 2005 5 Replies

Hi all,



I have written a user space program which traps keyboard input from several input sources using select() function on the /dev/input/eventX files.



It works nicely, but how can i detect from that same program if user decides to pull-out a USB connected keyboard or insert another in the USB port of the embedded Linux system ?



B.Rgds. Peter Denmark



Take a look at libusb

-- Marco Cavallini ===================================================== Koan s.a.s. - Software Engineering Linux and WinCE solutions for Embedded and Real-Time Software Klinux : the embedded distribution for industrial applications - Atmel AT91 ARM Third Party Consultant - Intel PCA Developer Network Member - Microsoft Windows Embedded Partner Via Pascoli, 3 - 24121 Bergamo - ITALIA Tel. +39-(0)35-255.235 - Fax +39-178-223.9748

formatting link
-
formatting link
=====================================================

The kernel is running the /sbin/hotplug executable in such a case. Do whatever yo need to do in this executabole which could be any kind of executable (bash-script,ELF-binary, etc.). You could simply send a signal from /sbin/hotplug to your Process which causes it to reopen devices e.g.

Sven

"If you continue running Windows, your system may become unstable." (Windows 95 BSOD) /me is giggls@ircnet, http://sven.gegg.us/ on the Web

Hi Sven,

Thank you for your input.

The /sbin/hotplug is not default installed on my ARM board running embedded Linux version 2.6.13.2. Is it a shell program or a binary executable ? Can it be cross compiled if binary ?

How can it "signal" my process ? Can it for example send a message or is it by calling another binary program ? Does hotplug tell mee which device i.e. keyboard, barcode scanner or other USB device has been changed ?

Peter

Ummm... Google for hotplug - 1st hit.

formatting link

Whatever you wand it to be. The Standard Linux hotplug script is written in bash and is somewhat slow for this reason. Have a look at

formatting link
for details.

I use a very small script in one of my applications for detecting USB events instead of the Standard script.

Using kill from whithin a shell-script or corresponding system-call from C.

Sven

Der "normale Bürger" ist nicht an der TU Dresden und schreibt auch nicht mit mutt. (Ulli Kuhnle in de.comp.os.unix.discussion) /me is giggls@ircnet, http://sven.gegg.us/ on the Web

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required