LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2007, 06:54 AM   #1
RichardS
Member
 
Registered: Jul 2007
Posts: 33

Rep: Reputation: 15
USB Mouse detection


Hi All,

I am currently playing with a USB mouse on an embedded version of Linux.

Is it possible to be notified when a USB mouse is plugged in?

The kernel has generic support for it, and I see some debug when the mouse is plugged in, but I was hoping for a more elegant solution than just polling the /dev/mouse device.

thanks,
Rich
 
Old 08-15-2007, 06:15 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Do you have udev set up? You can have it execute a command on a certain peripheral event. I use it to mount partitions and images when USB drives are plugged in. Look here: http://reactivated.net/writing_udev_rules.html
ta0kira
 
Old 08-16-2007, 02:08 AM   #3
RichardS
Member
 
Registered: Jul 2007
Posts: 33

Original Poster
Rep: Reputation: 15
Thanks. But I do not see how to udev. udev will create device nodes, but I am more looking for a coding solution. How do I detect the USB mouse within code, rather than getting a nice device node name?
 
Old 08-16-2007, 05:25 AM   #4
mann3r
LQ Newbie
 
Registered: Aug 2007
Posts: 2

Rep: Reputation: 0
i want to know this one too, for my current project I am developing for manufacturing
 
Old 08-16-2007, 06:20 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
In addition to creating a device, udev can execute a script. If you want your script to detect the connection rather than having it executed when the device is connected, have udev run a script that creates some indication that the device is connected which your script will check for. The same script can remove that indication when the device is no longer connected.
ta0kira
 
Old 08-16-2007, 06:31 AM   #6
RichardS
Member
 
Registered: Jul 2007
Posts: 33

Original Poster
Rep: Reputation: 15
Ok. But my programme is not a script. The only way I can think is that the script would send some sort of signal (e.g. SIGUSER1) and have the programme pickit up. Can scripts do this?
 
Old 08-16-2007, 08:00 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Yes. You need to know the PID or the name it's called under. With the PID do kill -s SIGUSR1 <pid> and with the script name do pkill -SIGUSR1 <name>. You must be careful to name the program something unique which won't be a part of something else's name. For example, "server" would be a good name to avoid.
ta0kira
 
Old 08-16-2007, 05:26 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
A better way to go with pkill would be pkill -SIGUSR1 ^<name>$. That will force only full-name matches and will send the signal to all processes under that name. I use pkill/pgrep constantly and they are very useful. You should also really check out that udev site. It's more versatile than you think.
ta0kira
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Gtk Mouse over detection PatrickNew Programming 11 04-02-2007 12:50 AM
Mouse detection Big Pussy Linux - Newbie 0 07-30-2006 08:54 AM
suse 10 + cannot connect to lan + no usb mouse detection adit_sen Linux - Hardware 0 03-06-2006 10:27 AM
Need Mouse and Keyboard Detection troutwaxer Slackware 0 10-14-2004 12:12 PM
USB mouse detection in Slackware 8.1 reaz82 Linux - General 3 04-15-2003 10:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration