zoukankan      html  css  js  c++  java
  • LINUX下如何控制小键盘灯的亮和灭

    http://topic.csdn.net/u/20081113/10/adfdd896-e7b3-437e-8e1e-9dbbeffb6ff3.html

    我有一个例子是让三个灯不断的在闪的

    例子如下:
    #include <stdio.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <signal.h>
    #include <sys/stat.h>
    #include <linux/kd.h>
    #include <sys/types.h>
    #include <sys/ioctl.h>
    #define ERROR -1
    int fd; /* File descriptor for console (/dev/tty/) */
    void sighandler(int signum);
    void main()
    {
      int i;
      /* To be used as the fd in ioctl(). */
      if ((fd = open("/dev/console", O_NOCTTY)) == ERROR)
    {
    perror("open");
    exit(ERROR);
    }
      signal(SIGINT, sighandler);
      signal(SIGTERM, sighandler);
      signal(SIGQUIT, sighandler);
      signal(SIGTSTP, sighandler);
      printf("w00w00!\n\n");
      printf("To exit hit Control-C.\n");
    while (1) 
      {
    for (i = 0x01; i <= 0x04; i++) 
    {
    /* We do this because there is no LED for 0x03. */
    if (i == 0x03) continue;
    usleep(50000);
    if ((ioctl(fd, KDSETLED, i)) == ERROR) {
    perror("ioctl");
    close(fd);
    exit(ERROR);
    }
    }
      }
    close(fd);
    }
    void sighandler(int signum)
    {
      /* Turn off all leds. No LED == 0x0. */
    if ((ioctl(fd, KDSETLED, 0x0)) == ERROR) 
      {
      perror("ioctl");
      close(fd);
      exit(ERROR);
      }
    printf("\nw00w00!\n");
    close(fd);
    exit(0);
    }

    ///////////////

    #define KDGETLED    0x4B31    /* return current led state */
    #define KDSETLED    0x4B32    /* set led state [lights, not flags] */
    #define     LED_SCR        0x01    /* scroll lock led */
    #define     LED_NUM        0x02    /* num lock led */
    #define     LED_CAP        0x04    /* caps lock led */


    每次切换前,记录当前scroll 、num 和caps 状态,即是否打开,然后
    ioctl(fd, KDSETLED, 0x0)) 关闭所有LED,
    然后点亮当前需要的key,其它的key根据上次状态恢复即可

    //////////////////////////////////////

  • 相关阅读:
    模型性能评估
    特征提取(机器学习数据预处理)
    决策树(DecisionTree)(附源码)
    支持向量机(SVM)
    Python机器学习/LogisticRegression(逻辑回归模型)(附源码)
    机器学习大致流程
    机器学习的数据预处理
    tensorflow的断点续训
    tensorboard可视化详细
    Linux启动tomcat
  • 原文地址:https://www.cnblogs.com/leaven/p/2318463.html
Copyright © 2011-2022 走看看