论坛: 编程破解 标题: GPM编程入门 复制本贴地址    
作者: GNU [gnu]    论坛用户   登录
Linux程式设计入门 - gpm


 

 

gpm是Linux console下的滑鼠驱动程式,它主要提供文字模式下的滑鼠事件处


理。Linux下文字界面的滑鼠几乎都是用gpm来处理。


 

gpm的文件在gpm原始码的doc目录中,详细的说明可叁考该目录中的文件gpm


programming guide,此处只提供给您KickStart的一些技巧及一些叁考说明。


 

特别注意到以下的范例,需在console下执行,不可在X Window的 Terminal下


执行。


 

 

范例 : gpm_mouse.c


 

gpm原始码中有一个mev.c的程式,主要用来测试滑鼠状态。事实上,mev.c是个


很好的范例,本范例便是取自mev.c,经过简化修改而来。


 

#include <stdio.h>


#include <stdlib.h>


#include <unistd.h>

#include <gpm.h>


 

void main(int argc,char **argv)


{


fd_set readset;


Gpm_Event event;


Gpm_Connect conn;


 

conn.eventMask = ~0;


conn.defaultMask = ~GPM_HARD;


conn.maxMod = 0;


conn.minMod = 0;


 

if (Gpm_Open(&conn,0)==-1) {


printf("Can not open mouse connection\n");


exit(1);


}


 

while (1) {


FD_ZERO(&readset);


FD_SET(gpm_fd,&readset);


select(gpm_fd+1,&readset,0,0,0);


 

if (FD_ISSET(gpm_fd,&readset)) {


if (Gpm_GetEvent(&event)>0) {


printf("mouse: event 0x%02X, at %2i %2i (delta %2i %2i),"


"button %i, modifiers 0x%02X\r\n", event.type,



event.x,event.y,


event.dx,event.dy,


event.buttons,


event.modifiers


);


}


}


}


 

while (Gpm_Close());


 

}


 

编译


 

gcc -o gpm_mouse gpm_mouse.c -lgpm


 

检验结果


 

mouse: event 0x01, at 15 1 (delta -2 -1),button 0, modifiers 0x00


mouse: event 0x01, at 14 1 (delta -1 0),button 0, modifiers 0x00


mouse: event 0x01, at 13 1 (delta -1 0),button 0, modifiers 0x00


 

 

资料结构


 

typedef struct Gpm_Connect {


unsigned short eventMask, defaultMask;


unsigned short minMod, maxMod;


int pid;


int vc;


} Gpm_Connect;


 

enum Gpm_Etype {


GPM_MOVE=1,


GPM_DRAG=2, /* exactly one of the bare ones is active at a time


*/


GPM_DOWN=4,


GPM_UP= 8,


 

GPM_SINGLE=16, /* at most one in three is set */


GPM_DOUBLE=32,


GPM_TRIPLE=64, /* WARNING: I depend on the values */


 

GPM_MFLAG=128, /* motion during click? */


GPM_HARD=256, /* if set in the defaultMask, force an


already used event to pass over to another handler */


 

GPM_ENTER=512, /* enter event, user in Roi's */


GPM_LEAVE=1024 /* leave event, used in Roi's */


};


 

typedef struct Gpm_Event {


unsigned char buttons, modifiers; /* try to be a multiple of 4 */


unsigned short vc;


short dx, dy, x, y;


enum Gpm_Etype type;


int clicks;


enum Gpm_Margin margin;


} Gpm_Event;


 

typedef int Gpm_Handler(Gpm_Event *event, void *clientdata);


 

函数宣告


 

int Gpm_Open(Gpm_Connect * CONN, int FLAGS);


int Gpm_Close(void);


int Gpm_GetEvent(Gpm_Event * EVENT);


int Gpm_Getc(FILE * fp);


#define Gpm_Getchar() Gpm_Getc(stdin)


int Gpm_Wgetch();


#define Gpm_Getch() (Gpm_Wgetch(NULL))


int Gpm_Repeat (int millisecs);


int Gpm_DrawPointer (int X, int Y, int FD);


int GPM_DRAWPOINTER (Gpm_Event *EPTR;)


int Gpm_FitValuesM (int *X, int *Y, int M int Gpm_FitValues (X,Y);


Gpm_FitEvent (EPTR);


char *Gpm_GetLibVersion (int *where);


char *Gpm_GetServerVersion (int *where);


int Gpm_GetSnapshot (Gpm_Event *ePtr);


 

 

OK STATION, Webmaster, Brian LinARGIN);


地主 发表时间: 04-09-08 20:32

回复: 天枫 [lqfrla]   论坛用户   登录


B1层 发表时间: 04-09-09 01:23

回复: SysHu0teR [syshunter]   版主   登录
很实用的东西, 建议有点C语言基础的多掌握这些

因为这东西只限制在console下,所以目前还在想怎么让这个东西在XTERM下也发挥作用。

希望大家踊跃发言,高手不吝赐教

B2层 发表时间: 04-09-09 13:11

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号