[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: detecting devices



On Sat, 2002-03-30 at 21:36, sangeetha wrote:
> hi,
>     is there anyway to detect whether devices(keyboard
> and mouse) are connected to system or
> not.........using c or assembly code on linux platform
> if so plz do let me know how we can do that.thanx in
> advance.

There are several places one can find this information, usually all
somewhere under /proc: /proc/pci or /proc/bus/pci for PCI cards,
/proc/bus/usb for USB devices, /proc/scsi for SCSI, /proc/ide for IDE,
and so on.  Poke around in /proc, and you might find what you're looking
for.

As for keyboards and mice: Keyboards aren't really detected; they're
assumed to be there, and there's no way to tell what key layout you have
w/o asking.  Detecting the mouse is more difficult; you actually have to
probe ports and look for certain kinds of responses.  This is especially
hard to do right when it comes to detecting serial mice, because of the
possibility that some other device might freak out if you probe the
serial port.

The exception to the above for both keyboards and mice is USB.  These
are easy to detect; just make sure you have hotplug, and look in
/proc/bus/usb.  You still can't figure out the key layout, but you can
ignore the exact type of the mouse, assume Microsoft Intellimouse, and
the driver will do the translation for you.

If you'd like some examples of Debian packages that perform the above
tasks, check out the discover, mdetect, and read-edid packages.  One
package that autodetects the keyboard, mouse, and monitor using these
tools is xserver-xfree86; check out how that package works for some
examples of hardware detection.


-- 
To UNSUBSCRIBE, email to debian-devel-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: