void mousemng_callback(HIPoint delta) { Point cp; if (!mousemng.flag) { getmaincenter(&cp); mousemng.x += (SINT16)delta.x; mousemng.y += (SINT16)delta.y; SetMouse(&cp); } }
static void mousecapture(BOOL capture) { Point cp; if (capture) { HideCursor(); getmaincenter(&cp); SetMouse(&cp); } else { ShowCursor(); } }
//集中 SetKeyBoard 和 SetMouse bool OutDevice::SetDevice() { if(m_devtype & MOUSE) { if(!SetMouse()) { return false; } } if(m_devtype & KEYBOARD) { if(!SetKeyBoard()) { return false; } } return true; }
void mousemng_callback(void) { Point p; Point cp; if (!mousemng.flag) { #if TARGET_API_MAC_CARBON SetPortWindowPort(hWndMain); #else SetPort(hWndMain); #endif GetMouse(&p); getmaincenter(&cp); mousemng.x += (SINT16)((p.h - cp.h) / 2); mousemng.y += (SINT16)((p.v - cp.v) / 2); SetMouse(&cp); } }
//======================================== // main... //---------------------------------------- int main (int argc, char*argv[]) { XF86MiscMouseSettings mseinfo; Display* dpy; int c; int DEBUG = False; int show = False; int Version = False; int apply = False; int enable = False; int disable = False; int major = 0; int minor = 0; char link [256] = ""; char mydisp [256] = ""; char option [256] = ""; char left [256] = ""; struct mouse *pointer; struct devnode *dev; struct stat *linkstatus = NULL; pointer = (struct mouse*) malloc(sizeof(struct mouse)); dev = (struct devnode*) malloc(sizeof(struct devnode)); // get commandline options... //----------------------------- while (1) { int option_index = 0; static struct option long_options[] = { {"show" , 0 , 0 , 's'}, {"apply" , 1 , 0 , 'a'}, {"display" , 1 , 0 , 'd'}, {"help" , 0 , 0 , 'h'}, {"link" , 1 , 0 , 'l'}, {"enable" , 0 , 0 , 'E'}, {"disable" , 0 , 0 , 'D'}, {"version" , 0 , 0 , 'v'}, {"config" , 0 , 0 , 'c'}, {0 , 0 , 0 , 0 } }; c = getopt_long (argc, argv, "hsa:d:l:EDvc",long_options, &option_index); if (c == -1) break; switch (c) { case 0: if (DEBUG) { fprintf (stderr,"option %s", long_options[option_index].name); if (optarg) fprintf (stderr," with arg %s", optarg); fprintf (stderr,"\n"); } break; case 'h': usage(); break; case 'c': showConfig(); break; case 's': show = True; break; case 'v': Version = True; break; case 'a': if (! IsRoot()) { fprintf(stderr,"xmset: only root can do this\n"); exit(1); } apply = True; strcpy(option,optarg); break; case 'l': // no longer used because we will get the // the device name (which may be a link) from the X-Server // and check if it is realy a link to the pointer device. // If not, no symlink is created after apply // --- // strcpy(link,optarg); break; case 'd': strcpy(mydisp,optarg); break; case 'E': if (! IsRoot()) { fprintf(stderr,"xmset: only root can do this\n"); exit(1); } enable = True; break; case 'D': if (! IsRoot()) { fprintf(stderr,"xmset: only root can do this\n"); exit(1); } disable = True; break; default: exit(1); } } // ... // open display... // --- if (strcmp(mydisp,"") == 0) { strcpy(mydisp,"null"); } dpy = XOpen(mydisp); if (dpy == NULL) { if (Version) { printf("0:6\n"); } else { fprintf(stderr,"xmset: could not open display\n"); } exit(1); } if (Version) { if (XF86MiscQueryVersion(dpy,&major,&minor)) { printf("%d:%d\n",major,minor); exit (0); } } // ... // store link name if the device specification // of the current configuration is a link // --- if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { fprintf(stderr,"xmset: could not get mouse settings\n"); exit(1); } if (apply == True) { linkstatus = (struct stat*)malloc(sizeof(struct stat)); lstat (mseinfo.device,linkstatus); if (S_ISLNK (linkstatus->st_mode)) { strcpy (link,mseinfo.device); } } //================================= // enable mouse //--------------------------------- if (enable == True) { XF86MiscMouseSettings mseinfo; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { exit(1); } mseinfo.flags |= MF_REOPEN; XSetErrorHandler (catchErrors); XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); exit(0); } //================================= // disable mouse //--------------------------------- if (disable == True) { XF86MiscMouseSettings mseinfo; if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { exit(1); } mseinfo.flags |= MF_REOPEN; mseinfo.device = "/dev/unused"; XSetErrorHandler (catchErrors); XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); exit(0); } //================================== // apply mouse settings //---------------------------------- if (apply == True) { XF86MiscMouseSettings mseinfo; strsplit (option,':',left,option); strcpy (pointer->device,left); strsplit (option,':',left,option); strcpy (pointer->type,left); strsplit (option,':',left,option); pointer->baudrate = atoi(left); strsplit (option,':',left,option); pointer->samplerate = atoi(left); strsplit (option,':',left,option); pointer->resolution = atoi(left); strsplit (option,':',left,option); pointer->buttons = atoi(left); strsplit (option,':',left,option); if (strcmp(left,"on") == 0) { strcpy(pointer->emu3button,"on"); } else { strcpy(pointer->emu3button,"off"); } strsplit(option,':',left,option); pointer->emu3timeout = atoi(left); strsplit(option,':',left,option); if (strcmp(left,"on") == 0) { strcpy(pointer->chordmiddle,"on"); } else { strcpy(pointer->chordmiddle,"off"); } strsplit (option,':',left,option); strcpy (pointer->flag,left); // ... // relink the /dev/sax link if the configuration // use a device link to point to the input device // --- if (S_ISLNK (linkstatus->st_mode)) { remove (link); symlink (pointer->device,link); } // ... // remove mouse from currently // accessed device // --- if (!XF86MiscGetMouseSettings(dpy, &mseinfo)) { exit(1); } mseinfo.flags |= MF_REOPEN; sprintf(mseinfo.device,"disabled"); XSetErrorHandler (catchErrors); XF86MiscSetMouseSettings(dpy, &mseinfo); XSync(dpy, False); // ... // set new mouse parameters... // --- usleep (1000); SetMouse (dpy,pointer); } //================================== // show current mouse settings //---------------------------------- if (show == True) { GetMouse(dpy); } return(0); }