//------------------------------------------------------------------- // trymouse.cpp // // This rudimentary demo shows how a Linux C++ application can // use the gpm server to respond to mouse and keyboard events. // It is based on a C example by Pradeep Padala (cited below). // // Compile using: g++ trymouse.c -lgpm -o trymouse // // Reference: Pradeep Padala, "Mouse Programming with libgpm" // online at: http://www.cise.ufl.edu/~ppadala/phd/libgpm.pdf // preliminary version of article submitted to Linux Journal. // // programmer: ALLAN CRUSE // written on: 14 AUG 2003 // revised on: 22 OCT 2003 //------------------------------------------------------------------- #include // for printf(), perror() #include // for Gpm_Open(), Gpm_Getc(), etc. #define KEY_ESCAPE 0x1B int my_handler( Gpm_Event *evt, void *data ) { printf( "Event type %d ", evt->type ); printf( "at x=%d y=%d ", evt->x, evt->y ); printf( "dx=%d dy=%d\n", evt->dx, evt->dy ); return 0; } int main( int argc, char **argv ) { // establish a connection with the gpm server-daemon Gpm_Connect conn; conn.eventMask = ~0; // we want to know about all events conn.defaultMask = 0; // don't handle anything by default conn.minMod = 0; // we want to know about everything conn.maxMod = ~0; // (info on any modifiers included) if ( Gpm_Open( &conn, 0 ) == -1 ) { perror( "cannot connect to mouse server" ); return 1; } // install our custom event-handler gpm_handler = my_handler; // main loop (to process canonical keyboard input) int c = 0; while ( ( c = Gpm_Getc( stdin ) ) != KEY_ESCAPE ); // close our connection with the gpm server-daemon Gpm_Close(); }