console3.txt

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

TXT
69
字号
Example: 
	This will turn off the Caps Lock LED and turn Caps Lock on. The
  reason we are turning the LED off is just to prove a point that just
  because the LED isn't on doesn't mean the flag isn't. This should show
  you how KDSKBLED differs from KDSETLED. This DOES NOT set the keyboard
  LED for Caps Lock on, this actually sets Caps Lock on. To set the LED as
  well use KDSETLED.

	#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

	void main()
	{
          int fd;
          int flag = 0x4;

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

	  printf("w00w00!\n\n");

          /* Turn off the Caps Lock LED just to show the difference */
          /* between KDSETLED and KDSKBLED. */
          if ((ioctl(fd, KDSETLED, 0x0)) == ERROR) {
	     perror("ioctl");
	     close(fd);
	     exit(ERROR);
	  }

          /* This turns Caps Lock itself, not the light. */ 
          if ((ioctl(fd, KDSKBLED, flag)) == ERROR) {
	     perror("ioctl");
	     close(fd);
	     exit(ERROR);
	  }

          printf("To show that Caps Lock is on even though the Caps"
                 "Lock LED isn't...\n");
          printf("Enter something: ");
          scanf("%s", NULL);

          /* Turn off any LEDs on (such as Numeric Lock) since we are */
          /* turning them all off with KDSKBLED right after this.     */
          if ((ioctl(fd, KDSETLED, 0x0)) == ERROR) {
	     perror("ioctl");
	     close(fd);
	     exit(ERROR);
	  }

          /* Now the Caps Lock is off. */ 
          if ((ioctl(fd, KDSKBLED, 0x0)) == ERROR) {
	     perror("ioctl");
	     close(fd);
	     exit(ERROR);
	  }
 
	  close(fd);
	}

⌨️ 快捷键说明

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