📄 kbd_tty.c
字号:
/* * Copyright (c) 1999 Greg Haerr <greg@censoft.com> * Copyright (c) 1991 David I. Bell * Permission is granted to use, distribute, or modify this source, * provided that this copyright notice remains intact. * * /dev/tty TTY Keyboard Driver * * Modified by joe to be used under minigui.2000/10/17 */#include <sys/types.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <termios.h>#include <fcntl.h>#include <sys/ioctl.h>#include <sys/stat.h>#ifndef __ECOS# include <linux/kd.h>#endif#include "common.h"#include "misc.h"#include "ial.h"#include "gal.h"#include "native.h"#define KEYBOARD "/dev/tty" /* keyboard associated with screen*/static int TTY_Open(void);static void TTY_Close(void);static void TTY_GetModifierInfo(int *modifiers);static int TTY_Read(unsigned char *buf, int *modifiers);KBDDEVICE kbddev = { TTY_Open, TTY_Close, TTY_GetModifierInfo, TTY_Read};static int kbd_fd; /* file descriptor for keyboard */static struct termios old_termios; /* original terminal modes */#ifndef __ECOSstatic int old_kbdmode;#endif/* * Open the keyboard. * This is real simple, we just use a special file handle * that allows non-blocking I/O, and put the terminal into * character mode. */static int TTY_Open(void){ struct termios new; /* new terminal modes */ kbd_fd = open(KEYBOARD, O_NONBLOCK); if (kbd_fd < 0) return -1; if (tcgetattr(kbd_fd, &old_termios) < 0) goto err; new = old_termios; new.c_lflag &= ~(ICANON | ECHO | ISIG); new.c_iflag &= ~(ISTRIP | IGNCR | ICRNL | INLCR | IXOFF | IXON); new.c_iflag |= IGNBRK; new.c_cc[VMIN] = 0; new.c_cc[VTIME] = 0; if(tcsetattr(kbd_fd, TCSAFLUSH, &new) < 0) goto err; /* Put the keyboard into MEDIUMRAW mode. Despite the name, this * is really "mostly raw", with the kernel just folding long * scancode sequences (e.g. E0 XX) onto single keycodes. */#ifndef __ECOS ioctl (kbd_fd,KDGKBMODE,&old_kbdmode); if (ioctl(kbd_fd, KDSKBMODE, K_MEDIUMRAW) < 0) goto err;#endif return kbd_fd;err: close(kbd_fd); kbd_fd = 0; return -1;}/* * Close the keyboard. * This resets the terminal modes. */static void TTY_Close(void){#ifndef __ECOS ioctl(kbd_fd, KDSKBMODE, old_kbdmode);#endif tcsetattr(kbd_fd, TCSANOW, &old_termios); close(kbd_fd); kbd_fd = 0;}/* * Return the possible modifiers for the keyboard. */static void TTY_GetModifierInfo(int *modifiers){ *modifiers = 0; /* no modifiers available */}/* * This reads one keystroke from the keyboard, and the current state of * the mode keys (ALT, SHIFT, CTRL). Returns -1 on error, 0 if no data * is ready, and 1 if data was read. This is a non-blocking call. */static int TTY_Read(unsigned char *buf, int *modifiers){ int cc; /* characters read */ unsigned char buf1; *modifiers = 0; /* no modifiers yet */ cc = read(kbd_fd, &buf1, 1); *buf = buf1; if (cc > 0) { return 1; } if ((cc < 0) && (errno != EINTR) && (errno != EAGAIN)) return -1; return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -