LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-07-2009, 05:35 PM   #1
lumpy2000
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Rep: Reputation: 0
Capture or monitor Mouse Button events in console


Hello!

I would like to ask question. Is there a way to monitor left and right mouse button events with bash script or maybe you have some advice in useful software that I could use with bash script. Or maybe somebody have samples with C/C++ code to shear (pity, but I am not an C/C++ programmer ).
My idea is based to be able to execute some scripts with mouse left and right buttons (if scrolling would also been available in some way, I would only by happier! ).
This computer is not installed with any X systems. System is based on Slackware and is installed on 128MB flash.

Any ideas wold by grateful!!

Last edited by lumpy2000; 02-07-2009 at 05:46 PM.
 
Old 02-10-2009, 02:45 AM   #2
lumpy2000
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Original Poster
Rep: Reputation: 0
In case somebody is interested in answer I got it with this C program:

#include <stdio.h>
#include <gpm.h>

int my_handler(Gpm_Event *event, void *data)
{ if(event->type & GPM_DOWN)
{ if(event->buttons & GPM_B_LEFT)
system("./l.sh");
if(event->buttons & GPM_B_RIGHT)
system("./r.sh");
if(event->buttons & GPM_B_MIDDLE)
system("./m.sh");
}
return 0;
}

int main()
{ Gpm_Connect conn;
int c;
conn.eventMask = ~0; /* Want to know about all the events */
conn.defaultMask = 0; /* don't handle anything by default */
conn.minMod = 0; /* want everything */

if(Gpm_Open(&conn, 0) == -1)
printf("Cannot connect to mouse server\n");
gpm_handler = my_handler;
while((c = Gpm_Getc(stdin)) != EOF)
Gpm_Close();
return 0;
}
/*EOF*/

All you have to do is save code with mouse.c file name and compile it : gcc -o mouse mouse.c -lgpm
and you got a "mouse" program that executes l.sh on left, r.sh on right and m.sh on middle mouse button click.

You will also have to install gpm daemon (and run it) and libgpm.

There is one issue, I can't get mouse wheel work whit libgpm. libgpm have very poor documentary so maybe someone knows how to read wheel events?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Keyboard events interrupting mouse events. miner49er Linux - Hardware 3 11-04-2008 04:16 AM
Capture Windows Events erat123 Programming 1 07-05-2007 11:10 AM
Weird - Mouse button events for keyboard keypresses? pavgust Linux - Hardware 1 06-17-2004 04:44 AM
middle mouse button is paste.. but what if i dont have a mid mouse button? kublador Linux - Newbie 4 09-02-2003 08:59 AM
how to capture mouse and keyboard events programatically karthikeyan Programming 3 02-21-2003 07:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:46 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