📄 00000004.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: reden (Offer 快快来啊 ~!), 信区: Linux <BR>标 题: Linux程式设计入门 - gpm <BR>发信站: BBS 水木清华站 (Thu Apr 1 19:58:22 1999) <BR> <BR>Linux程式设计入门 - gpm <BR> <BR> <BR> <BR> gpm是Linux console下的滑鼠驱动程式,它主要提供文字模式下的滑鼠事件处 <BR> <BR> 理。Linux下文字界面的滑鼠几乎都是用gpm来处理。 <BR> <BR> <BR> gpm的文件在gpm原始码的doc目录中,详细的说明可叁考该目录中的文件gpm <BR> <BR> programming guide,此处只提供给您KickStart的一些技巧及一些叁考说明。 <BR> <BR> <BR> 特别注意到以下的范例,需在console下执行,不可在X Window的 Terminal下 <BR> <BR> 执行。 <BR> <BR> <BR> <BR> 范例 : gpm_mouse.c <BR> <BR> <BR> gpm原始码中有一个mev.c的程式,主要用来测试滑鼠状态。事实上,mev.c是个 <BR> <BR> 很好的范例,本范例便是取自mev.c,经过简化修改而来。 <BR> <BR> <BR> #include <stdio.h> <BR> <BR> #include <stdlib.h> <BR> <BR> #include <unistd.h> <BR> <BR> #include <gpm.h> <BR> <BR> <BR> void main(int argc,char **argv) <BR> <BR> { <BR> <BR> fd_set readset; <BR> <BR> Gpm_Event event; <BR> <BR> Gpm_Connect conn; <BR> <BR> <BR> conn.eventMask = ~0; <BR> <BR> conn.defaultMask = ~GPM_HARD; <BR> <BR> conn.maxMod = 0; <BR> <BR> conn.minMod = 0; <BR> <BR> <BR> if (Gpm_Open(&conn,0)==-1) { <BR> <BR> printf("Can not open mouse connection\n"); <BR> <BR> exit(1); <BR> <BR> } <BR> <BR> <BR> while (1) { <BR> <BR> <BR> FD_ZERO(&readset); <BR> <BR> FD_SET(gpm_fd,&readset); <BR> <BR> select(gpm_fd+1,&readset,0,0,0); <BR> <BR> <BR> if (FD_ISSET(gpm_fd,&readset)) { <BR> <BR> if (Gpm_GetEvent(&event)>0) { <BR> <BR> printf("mouse: event 0x%02X, at %2i %2i (delta %2i %2i)," <BR> <BR> "button %i, modifiers 0x%02X\r\n", <BR> <BR> event.type, <BR> <BR> event.x,event.y, <BR> <BR> event.dx,event.dy, <BR> <BR> event.buttons, <BR> <BR> event.modifiers <BR> <BR> ); <BR> <BR> } <BR> <BR> } <BR> <BR> } <BR> <BR> <BR> while (Gpm_Close()); <BR> <BR> <BR> } <BR> <BR> <BR> 编译 <BR> <BR> <BR> gcc -o gpm_mouse gpm_mouse.c -lgpm <BR> <BR> <BR> 检验结果 <BR> <BR> <BR> mouse: event 0x01, at 15 1 (delta -2 -1),button 0, modifiers 0x00 <BR> <BR> mouse: event 0x01, at 14 1 (delta -1 0),button 0, modifiers 0x00 <BR> <BR> mouse: event 0x01, at 13 1 (delta -1 0),button 0, modifiers 0x00 <BR> <BR> <BR> <BR> 资料结构 <BR> <BR> <BR> typedef struct Gpm_Connect { <BR> <BR> unsigned short eventMask, defaultMask; <BR> <BR> unsigned short minMod, maxMod; <BR> <BR> int pid; <BR> <BR> int vc; <BR> <BR> } Gpm_Connect; <BR> <BR> <BR> enum Gpm_Etype { <BR> <BR> GPM_MOVE=1, <BR> <BR> GPM_DRAG=2, /* exactly one of the bare ones is active at a time <BR> <BR> */ <BR> <BR> GPM_DOWN=4, <BR> <BR> GPM_UP= 8, <BR> <BR> <BR> GPM_SINGLE=16, /* at most one in three is set */ <BR> <BR> GPM_DOUBLE=32, <BR> <BR> GPM_TRIPLE=64, /* WARNING: I depend on the values */ <BR> <BR> <BR> GPM_MFLAG=128, /* motion during click? */ <BR> <BR> GPM_HARD=256, /* if set in the defaultMask, force an <BR> <BR> already used event to pass over to another handler */ <BR> <BR> <BR> GPM_ENTER=512, /* enter event, user in Roi's */ <BR> <BR> GPM_LEAVE=1024 /* leave event, used in Roi's */ <BR> <BR> }; <BR> <BR> <BR> typedef struct Gpm_Event { <BR> <BR> unsigned char buttons, modifiers; /* try to be a multiple of 4 */ <BR> <BR> unsigned short vc; <BR> <BR> short dx, dy, x, y; <BR> <BR> enum Gpm_Etype type; <BR> <BR> int clicks; <BR> <BR> enum Gpm_Margin margin; <BR> <BR> } Gpm_Event; <BR> <BR> <BR> typedef int Gpm_Handler(Gpm_Event *event, void *clientdata); <BR> <BR> <BR> 函数宣告 <BR> <BR> <BR> int Gpm_Open(Gpm_Connect * CONN, int FLAGS); <BR> <BR> int Gpm_Close(void); <BR> <BR> int Gpm_GetEvent(Gpm_Event * EVENT); <BR> <BR> int Gpm_Getc(FILE * fp); <BR> <BR> #define Gpm_Getchar() Gpm_Getc(stdin) <BR> <BR> int Gpm_Wgetch(); <BR> <BR> #define Gpm_Getch() (Gpm_Wgetch(NULL)) <BR> <BR> int Gpm_Repeat (int millisecs); <BR> <BR> int Gpm_DrawPointer (int X, int Y, int FD); <BR> <BR> int GPM_DRAWPOINTER (Gpm_Event *EPTR;) <BR> <BR> int Gpm_FitValuesM (int *X, int *Y, int MARGIN); <BR> <BR> int Gpm_FitValues (X,Y); <BR> <BR> Gpm_FitEvent (EPTR); <BR> <BR> char *Gpm_GetLibVersion (int *where); <BR> <BR> char *Gpm_GetServerVersion (int *where); <BR> <BR> int Gpm_GetSnapshot (Gpm_Event *ePtr); <BR> <BR> <BR> <BR> OK STATION, Webmaster, Brian Lin <BR> <BR> <BR> <BR> <BR>-- <BR>在江湖中,只要拿起了刀,就是一场无涯的梦。 <BR> <BR>※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 159.226.21.168] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -