console1.txt

来自「linux/kd.h文件中介绍了ioctl函数能够使用的命令」· 文本 代码 · 共 55 行

TXT
55
字号
Example:
	#include <stdio.h>
	#include <fcntl.h>
        #include <sys/stat.h>
	#include <linux/kd.h>  /* Keyboard IOCTLs */
	#include <sys/ioctl.h> /* ioctl()         */
	#include <sys/types.h>
 
        #define ERROR -1

        void checkleds();

	void main()
        {
          int fd;       /* Console fd (/dev/tty). Used as fd in ioctl() */
          long int arg; /* Where the LED states will be put into.       */

          /* To use as the fd in ioctl(). */
          if ((fd = open("/dev/tty", O_NOCTTY)) == ERROR) {
	     perror("open");
	     exit(ERROR);
          }

          /* Value stored in arg. */
	  if (ioctl(fd, KDGETLED, &arg) == ERROR) {
	     perror("ioctl");
	     close(fd);
	     exit(ERROR);
          }

          /* Here we print out current LEDS. */
          checkleds();
        }

        void checkleds()
        {
          /* LED_SCR = 0x1, LED_NUM = 0x2, LED_CAP = 0x4 */

          if (arg == LED_SCR) printf("Scroll Lock LED is on.\n");
	  else if (arg == LED_NUM) printf("Numeric Lock LED is on.\n");
	  else if (arg == LED_CAP) printf("Caps Lock LED is on.\n");

          else if (arg == LED_NUM + LED_CAP) 
             printf("Numeric Lock and Caps Lock LEDs are on.\n");

          else if (arg == LED_NUM + LED_SCR) 
             printf("Numeric Lock and Scroll Lock LEDs are on.\n");

	  else if (arg == LED_CAP + LED_SCR) 
	     printf("Caps Lock and Scroll Lock LEDs are on.\n");

          else if (arg == LED_NUM + LED_SCR + LED_CAP) 
             printf("Numeric Lock, Scroll Lock, and Caps Lock LEDs are on.\n");

        }

⌨️ 快捷键说明

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