Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

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


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 06:46 PM.
Old 02-10-2009, 03:45 AM   #2
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)
if(event->buttons & GPM_B_RIGHT)
if(event->buttons & GPM_B_MIDDLE)
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)
return 0;

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 on left, on right and 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?


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

All times are GMT -5. The time now is 09:35 PM.

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