Linux text mode to listen to mouse events, here is done by the GPM, the code is as follows:
1#include <stdio.h>2#include <stdlib.h>3#include <unistd.h>4#include <gpm.h>5 6 voidMainintargcChar**argv)7 { 8 fd_set Readset;9Gpm_eventEvent; Ten Gpm_connect Conn; One AConn.eventmask = ~0; -Conn.defaultmask = ~Gpm_hard; -Conn.maxmod =0; theConn.minmod =0; - - if(Gpm_open (&conn,0)==-1) { -printf"Can not open mouse connection\n"); +Exit1); - } + A at while(1) { -Fd_zero (&readset); -Fd_set (gpm_fd,&readset); - Select(gpm_fd+1, &readset,0,0,0); - - if(Fd_isset (gpm_fd,&Readset)) { in if(Gpm_getevent (&Event) >0) { -printf"mouse:event 0x%02X, at%2i%2i (Delta%2i%2i)," to "button%i, modifiers 0x%02x\r\n", + Event. Type, - Event. x,Event. Y, the Event. DX,Event. Dy, * Event. Buttons, $ Event. ModifiersPanax Notoginseng ); - } the } + } A while(Gpm_close ()); the}
Compile:
gcc -o mouse Mouse.c-lgmp
If your machine does not have GMP installed, please install Gmp,centos 6.0 with the following command to install the network:
sudo Install gpm*
I have chosen to install the following libraries:
gpmgpm-develgpm-static
Note: This article is selected from Http://topic.csdn.net/u/20090407/23/f776fdca-c41b-4478-9fd5-93f61cfbbe92.html,
If infringement of your interests, please email me, I will be notified as soon as possible after the deletion of the relevant content.
Monitor mouse events in Linux text mode