Monitor mouse events in Linux text mode

Source: Internet
Author: User
Tags gmp modifiers

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.