gcc mousekey.c -lX11 -IX11
打开mousekeys运行./a.out
关闭mousekeys运行./a.out 1,这里在a.out后面随便加一个参数就可以了,因为判断条件为 if(argc < 2)
/*********source code***************/
#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
int main(int argc, char *argv[])
{
Display *display;
unsigned long which;
XkbDescPtr xkb;
unsigned int status_mask = 0;
unsigned short mk_delay = 160;
unsigned short mk_interval = 50;
unsigned short mk_time_to_max = 30;
unsigned short mk_max_speed = 50;
short mk_curve = 0;
Status S;
status_mask = XkbMouseKeysMask;
display = XOpenDisplay(NULL);
xkb = XkbGetMap(display, 0, XkbUseCoreKbd);
if((int)xkb == BadAlloc || xkb == NULL)
{
printf("ERROR: unable to allocate storege./n");
return 1;
}
if((S = XkbGetControls(display, XkbAllControlsMask, xkb)) != Success)
{
if(S == BadAlloc)
printf("ERROR: Unable to allocate storage./n");
else if(S == BadMatch)
printf("ERROR: Unable to query state of keyboard./n");
else printf("ERROR: Unable to get state of keyboard controls. /n");
return 2;
}
unsigned int changeEnabled = 0;
unsigned int enabled = 0;
changeEnabled |=status_mask;
if(argc < 2)
enabled |= status_mask;
if(xkb->ctrls)
{
xkb->ctrls->enabled_ctrls &=~changeEnabled;
xkb->ctrls->enabled_ctrls |=(changeEnabled & enabled);
xkb->ctrls->mk_delay = mk_delay;
xkb->ctrls->mk_interval = mk_interval;
xkb->ctrls->mk_time_to_max = mk_time_to_max;
xkb->ctrls->mk_max_speed = mk_max_speed;
xkb->ctrls->mk_curve = mk_curve;
}
else
{
printf("ERROR: Unable to get state of keyboard controls./n");
return 3;
}
if(!XkbSetControls(display, status_mask | XkbControlsEnabledMask, xkb))
{
printf("ERROR: Unable to set state of keyboard controls./n");
return 4;
}
XkbGetControls(display, XkbAllControlsMask, xkb);
XkbFreeKeyboard(xkb, status_mask, True);
XCloseDisplay(display);
return 0;
}