⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 console13.txt

📁 linux/kd.h文件中介绍了ioctl函数能够使用的命令
💻 TXT
字号:
Example:
	#include <stdio.h>
	#include <fcntl.h>
        #include <errno.h>
	#include <unistd.h>
	#include <sys/stat.h>
	#include <linux/kd.h>
	#include <sys/types.h>
	#include <sys/ioctl.h>

	#define ERROR -1
        #define NR_KEYS 128
        #define MAX_NR_KEYMAPS 256

	void main()
	{
          int fd;
          register int i, j;
          struct kbentry kbent;

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

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

          kbent.kb_table = 0; /* Keyboard maps at table element 0 */
          kbent.kb_index = 0; /* Index into keyboard map          */


          for (i = 0; i <= MAX_NR_KEYMAPS; i++) {
              for (j = 0; j <= NR_KEYS; j++) {
                  if (ioctl(fd, KDGKBENT, &kbent) == ERROR) {
		     if (errno == EINVAL) continue;
                     else { 
                        perror("ioctl");
                        close(fd);
			exit(ERROR);
		     }
                  }

                  usleep(20000); /* To slow output. */

                  /* Skip over no such, or in an invalid map. */
                  if ((kbent.kb_value   == K_HOLE) 
                     || (kbent.kb_value == K_NOSUCHMAP)) continue;

                  if (!isprint(kbent.kb_value)) {
                      printf("Skipped unprintable character at: "
                             "Table %d, Index %d\n", 
                             kbent.kb_table, kbent.kb_index);

       	  	      kbent.kb_index++;
  		      continue;
	          }

                  printf("Table: %d, Index: %d, ", 
                         kbent.kb_table, kbent.kb_index);

                  kbent.kb_index++;

                  printf("Key: %c (0x%x)\n", kbent.kb_value, kbent.kb_value);

              }

              j = 0;
              kbent.kb_index = j;
              kbent.kb_table = i;
          }

          putchar('\n');
   	  close(fd);
      }

⌨️ 快捷键说明

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