Return to Snippet

Revision: 72726
at November 18, 2017 09:02 by xyzeugene

Initial Code
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;

Initial URL

Initial Description
Install GPM using installer such as  apt or dnf 

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?

Initial Title
C Program to read mouse in console via GPM

Initial Tags
c, linux

Initial Language