Thread: Detecting keyboard and mouse in linux

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Detecting keyboard and mouse in linux

    Hello guys,
    i am writing a c program to detect the keyboard and mouse. In fact i am doing it right now by reading the file /proc/bus/input/devices. Program is working with few exceptions.
    First problem is if you remove ps2 mouse or keyboard there is no change in /proc/bus/input/devices so it is still showing mouse and keyboard is connected when it is not. It works fine with USB Keyboard and mouse though.(it works ps2 but needs system reboot only then /proc/bus/input/devices file reflects changes.)
    Second i am looking for the string "mouse" and "keyboard" in this file(obviously bad idea). For some keyboards and mice there is no string "mouse" and "keyboard" in the entry NAME:<name of device> .
    so i am looking for some way i can do it without using string comparison and which works for ps2.
    i am using 2.6.21-1.3194.fc7.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    ps2 does not support "hot plugging", so the OS has not got any possibility to detect that the device is attached or detached once it's up and running. You could possibly access the driver and see if it can send something to the keyboard that will give a response and then see if you get a timeout - I know that blinking the keyboar LED's will give a response back from the keyboard. I'm not sure about mice, but I'm pretty sure there is something you could send to the mouse and get a response.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    5
    Can i send some signal on the bus connecting keyboard and mouse, and if i recieve something back then i will say it is connected. Can something like this be done?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by sameer.nalwade View Post
    Can i send some signal on the bus connecting keyboard and mouse, and if i recieve something back then i will say it is connected. Can something like this be done?
    Yes, but you need to have a driver to do that, and unless you also want to prevent the keyboard from working properly, then you will have to use the existing driver (or modify the standard keyboard/mouse driver in some way).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to handle keyboard and mouse events for all windows
    By manav-II in forum Windows Programming
    Replies: 3
    Last Post: 08-25-2008, 09:03 AM
  2. GLUT keyboard and mouse func separated
    By krappa in forum Game Programming
    Replies: 1
    Last Post: 04-20-2005, 06:27 PM
  3. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  4. Mouse & keyboard deactivate for some seconds?
    By JoJo in forum Windows Programming
    Replies: 0
    Last Post: 09-08-2001, 12:18 PM
  5. Replies: 0
    Last Post: 09-08-2001, 06:51 AM