xleds.c

来自「Linux下的一个用于控制xwindow下的numlock键及caps键开/关的」· C语言 代码 · 共 88 行

C
88
字号
/* Xleds.c * * Copyright (C) 2000 Michael McTernan  mm7323@bris.ac.uk * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */#include <stdio.h>#include <sys/syslog.h>#include <X11/extensions/XTest.h>#include <X11/keysym.h>static Display *theDisplay=NULL;/* Prototype */void setLeds(int num,int caps,int scr);static void set(int led,int mode);int main() {  /* Attempt to open the default display */  if((theDisplay=XOpenDisplay(NULL))==NULL) {    syslog(LOG_ERR,"Failed to open display.");    fprintf(stderr,"Failed to open display.");  }  setLeds(1,0,0);  sleep(1);  setLeds(0,1,0);  sleep(1);  setLeds(0,0,1);  sleep(1);  setLeds(0,1,0);  sleep(1);  setLeds(1,0,0);}void setLeds(int num,int caps,int scr) {  printf("%d %d %d\n",num,caps,scr);  if(num)    set(1,LedModeOn);  else    set(1,LedModeOff);  if(caps)    set(2,LedModeOn);  else    set(2,LedModeOff);  if(scr)    set(3,LedModeOn);  else    set(3,LedModeOff);  XSync(theDisplay,False);}/*set*//* Sets led to mode */static void set(int led,int mode) {  XKeyboardControl values;  values.led=led;    values.led_mode=mode;   XChangeKeyboardControl(theDisplay, KBLedMode,&values);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?