Enable/Disable Linux mousekeys

 

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值