LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Capture or monitor Mouse Button events in console (https://www.linuxquestions.org/questions/linux-software-2/capture-or-monitor-mouse-button-events-in-console-703018/)

lumpy2000 02-07-2009 05:35 PM

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!!

lumpy2000 02-10-2009 02:45 AM

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?


All times are GMT -5. The time now is 12:23 PM.