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

📄 kbd.c

📁 ELinks is an advanced and well-established feature-rich text mode web (HTTP/FTP/..) browser. ELinks
💻 C
📖 第 1 页 / 共 2 页
字号:
{KBD_BS,KBD_ALT},{0,0},/* 16 */{'Q',KBD_ALT},{'W',KBD_ALT},{'E',KBD_ALT},{'R',KBD_ALT},{'T',KBD_ALT},{'Y',KBD_ALT},{'U',KBD_ALT},{'I',KBD_ALT},/* 24 */{'O',KBD_ALT},{'P',KBD_ALT},{'[',KBD_ALT},{']',KBD_ALT},{KBD_ENTER,KBD_ALT},{0,0},{'A',KBD_ALT},{'S',KBD_ALT},/* 32 */{'D',KBD_ALT},{'F',KBD_ALT},{'G',KBD_ALT},{'H',KBD_ALT},{'J',KBD_ALT},{'K',KBD_ALT},{'L',KBD_ALT},{';',KBD_ALT},/* 40 */{'\'',KBD_ALT},{'`',KBD_ALT},{0,0},{'\\',KBD_ALT},{'Z',KBD_ALT},{'X',KBD_ALT},{'C',KBD_ALT},{'V',KBD_ALT},/* 48 */{'B',KBD_ALT},{'N',KBD_ALT},{'M',KBD_ALT},{',',KBD_ALT},{'.',KBD_ALT},{'/',KBD_ALT},{0,0},{'*',KBD_ALT},/* 56 */{0,0},{' ',KBD_ALT},{0,0},{KBD_F1,0},{KBD_F2,0},{KBD_F3,0},{KBD_F4,0},{KBD_F5,0},/* 64 */{KBD_F6,0},{KBD_F7,0},{KBD_F8,0},{KBD_F9,0},{KBD_F10,0},{0,0},{0,0},{KBD_HOME,0},/* 72 */{KBD_UP,0},{KBD_PAGE_UP,0},{'-',KBD_ALT},{KBD_LEFT,0},{'5',0},{KBD_RIGHT,0},{'+',KBD_ALT},{KBD_END,0},/* 80 */{KBD_DOWN,0},{KBD_PAGE_DOWN,0},{KBD_INS,0},{KBD_DEL,0},{0,0},{0,0},{0,0},{0,0},/* 88 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{KBD_F1,KBD_CTRL},{KBD_F2,KBD_CTRL},/* 96 */{KBD_F3,KBD_CTRL},{KBD_F4,KBD_CTRL},{KBD_F5,KBD_CTRL},{KBD_F6,KBD_CTRL},{KBD_F7,KBD_CTRL},{KBD_F8,KBD_CTRL},{KBD_F9,KBD_CTRL},{KBD_F10,KBD_CTRL},/* 104 */{KBD_F1,KBD_ALT},{KBD_F2,KBD_ALT},{KBD_F3,KBD_ALT},{KBD_F4,KBD_ALT},{KBD_F5,KBD_ALT},{KBD_F6,KBD_ALT},{KBD_F7,KBD_ALT},{KBD_F8,KBD_ALT},/* 112 */{KBD_F9,KBD_ALT},{KBD_F10,KBD_ALT},{0,0},{KBD_LEFT,KBD_CTRL},{KBD_RIGHT,KBD_CTRL},{KBD_END,KBD_CTRL},{KBD_PAGE_DOWN,KBD_CTRL},{KBD_HOME,KBD_CTRL},/* 120 */{'1',KBD_ALT},{'2',KBD_ALT},{'3',KBD_ALT},{'4',KBD_ALT},{'5',KBD_ALT},{'6',KBD_ALT},{'7',KBD_ALT},{'8',KBD_ALT},/* 128 */{'9',KBD_ALT},{'0',KBD_ALT},{'-',KBD_ALT},{'=',KBD_ALT},{KBD_PAGE_UP,KBD_CTRL},{KBD_F11,0},{KBD_F12,0},{0,0},/* 136 */{0,0},{KBD_F11,KBD_CTRL},{KBD_F12,KBD_CTRL},{KBD_F11,KBD_ALT},{KBD_F12,KBD_ALT},{KBD_UP,KBD_CTRL},{'-',KBD_CTRL},{'5',KBD_CTRL},/* 144 */{'+',KBD_CTRL},{KBD_DOWN,KBD_CTRL},{KBD_INS,KBD_CTRL},{KBD_DEL,KBD_CTRL},{KBD_TAB,KBD_CTRL},{0,0},{0,0},{KBD_HOME,KBD_ALT},/* 152 */{KBD_UP,KBD_ALT},{KBD_PAGE_UP,KBD_ALT},{0,0},{KBD_LEFT,KBD_ALT},{0,0},{KBD_RIGHT,KBD_ALT},{0,0},{KBD_END,KBD_ALT},/* 160 */{KBD_DOWN,KBD_ALT},{KBD_PAGE_DOWN,KBD_ALT},{KBD_INS,KBD_ALT},{KBD_DEL,KBD_ALT},{0,0},{KBD_TAB,KBD_ALT},{KBD_ENTER,KBD_ALT},{0,0},/* 168 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},/* 176 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},/* 192 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},/* 208 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},/* 224 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},/* 240 */{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},/* 256 */};int xterm_button = -1;int process_queue(struct itrm *itrm){	struct event ev = {EV_KBD, -1, 0, 0};	int el = 0;	if (!itrm->qlen) goto end;	if (itrm->kqueue[0] == '\033') {		if (itrm->qlen < 2) goto ret;		if (itrm->kqueue[1] == '[' || itrm->kqueue[1] == 'O') {			char c;			int v;			if (itrm->qlen >= 4 && itrm->kqueue[2] == '[') {				if (itrm->kqueue[3] < 'A' || itrm->kqueue[3] > 'L') goto ret;				ev.x = KBD_F1 - (itrm->kqueue[3] - 'A');				el = 4;			} else if (get_esc_code(itrm->kqueue, itrm->qlen, &c, &v, &el)) goto ret;			else switch (c) {				case '@': ev.x = KBD_INS; break;				case 'A': ev.x = KBD_UP; break;				case 'B': ev.x = KBD_DOWN; break;				case 'C': ev.x = KBD_RIGHT; break;				case 'D': ev.x = KBD_LEFT; break;				case 'F':				case 'e': ev.x = KBD_END; break;				case 'H':				case 0: ev.x = KBD_HOME; break;				case 'V':				case 'I': ev.x = KBD_PAGE_UP; break;				case 'U':				case 'G': ev.x = KBD_PAGE_DOWN; break;				case 'P': ev.x = KBD_F1; break;				case 'Q': ev.x = KBD_F2; break;				case 'S': ev.x = KBD_F4; break;				case 'T': ev.x = KBD_F5; break;				case 'W': ev.x = KBD_F8; break;				case 'X': ev.x = KBD_F9; break;				case 'Y': ev.x = KBD_F11; break;				case 'z': switch (v) {					case 247: ev.x = KBD_INS; break;					case 214: ev.x = KBD_HOME; break;					case 220: ev.x = KBD_END; break;					case 216: ev.x = KBD_PAGE_UP; break;					case 222: ev.x = KBD_PAGE_DOWN; break;					case 249: ev.x = KBD_DEL; break;					} break;				case '~': switch (v) {					case 1: ev.x = KBD_HOME; break;					case 2: ev.x = KBD_INS; break;					case 3: ev.x = KBD_DEL; break;					case 4: ev.x = KBD_END; break;					case 5: ev.x = KBD_PAGE_UP; break;					case 6: ev.x = KBD_PAGE_DOWN; break;					case 7: ev.x = KBD_HOME; break;					case 8: ev.x = KBD_END; break;					case 17: ev.x = KBD_F6; break;					case 18: ev.x = KBD_F7; break;					case 19: ev.x = KBD_F8; break;					case 20: ev.x = KBD_F9; break;					case 21: ev.x = KBD_F10; break;					case 23: ev.x = KBD_F11; break;					case 24: ev.x = KBD_F12; break;					} break;				case 'R':					resize_terminal();					break ;				case 'M': if (itrm->qlen - el < 3) goto ret;					if (v == 5) {						if (xterm_button == -1) xterm_button = 0; /* */						if (itrm->qlen - el < 5) goto ret;						ev.x = (unsigned char)(itrm->kqueue[el+1]) - ' ' - 1 + ((int)((unsigned char)(itrm->kqueue[el+2]) - ' ' - 1) << 7);						if ( ev.x & (1 << 13)) ev.x = 0; /* ev.x |= ~0 << 14; */						ev.y = (unsigned char)(itrm->kqueue[el+3]) - ' ' - 1 + ((int)((unsigned char)(itrm->kqueue[el+4]) - ' ' - 1) << 7);						if ( ev.y & (1 << 13)) ev.y = 0; /* ev.y |= ~0 << 14; */						switch ((itrm->kqueue[el] - ' ') ^ xterm_button) { /* Every event changhes only one bit */						    case TW_BUTT_LEFT:   ev.b = B_LEFT | ( (xterm_button & TW_BUTT_LEFT) ? B_UP : B_DOWN ); break; 						    case TW_BUTT_MIDDLE: ev.b = B_MIDDLE | ( (xterm_button & TW_BUTT_MIDDLE) ? B_UP :  B_DOWN ); break;						    case TW_BUTT_RIGHT:  ev.b = B_RIGHT | ( (xterm_button & TW_BUTT_RIGHT) ? B_UP : B_DOWN ); break;						    case 0: ev.b = B_DRAG;						    /* default : Twin protocol error */						}						xterm_button = itrm->kqueue[el] - ' ';						el += 5;					} else {						ev.x = itrm->kqueue[el+1] - ' ' - 1;						ev.y = itrm->kqueue[el+2] - ' ' - 1;						ev.b = B_DOWN;						if (itrm->kqueue[el] & 4) ev.b = B_DRAG;						if ((ev.b |= (itrm->kqueue[el] & BM_BUTT) | B_DOWN) == 3) {							ev.b = B_UP;							if (xterm_button != -1) ev.b |= xterm_button;						}  						/*if ((itrm->kqueue[el] & 4) && ev.b != B_UP) ev.b |= B_DRAG;*/						xterm_button = -1;						if ((ev.b & BM_ACT) == B_DOWN) xterm_button = ev.b & BM_BUTT;						el += 3;					}					ev.ev = EV_MOUSE;					break;			}		} else {			el = 2;			if (itrm->kqueue[1] == '\033') {				if (itrm->qlen >= 3 && (itrm->kqueue[2] == '[' || itrm->kqueue[2] == 'O')) el = 1;				ev.x = KBD_ESC;				goto l2;			} else if (itrm->kqueue[1] == 127) {				ev.x = KBD_DEL;				ev.y = 0;				goto l2;			} else {				ev.x = itrm->kqueue[1];				ev.y |= KBD_ALT;				goto l2;			}		}		goto l1;	} else if (itrm->kqueue[0] == 0) {		if (itrm->qlen < 2) goto ret;		if (!(ev.x = os2xtd[itrm->kqueue[1]].x)) ev.x = -1;		ev.y = os2xtd[itrm->kqueue[1]].y;		el = 2;		/*printf("%02x - %02x %02x\n", (int)itrm->kqueue[1], ev.x, ev.y);*/		goto l1;	}	el = 1;	ev.x = itrm->kqueue[0];	l2:	/*if (ev.x == 1) ev.x = KBD_HOME;	if (ev.x == 2) ev.x = KBD_PAGE_UP;	if (ev.x == 4) ev.x = KBD_DEL;	if (ev.x == 5) ev.x = KBD_END;	if (ev.x == 6) ev.x = KBD_PAGE_DOWN;*/	if (ev.x == 8) ev.x = KBD_BS;	if (ev.x == 9) ev.x = KBD_TAB;	if (ev.x == 10) ev.x = KBD_ENTER/*, ev.y = KBD_CTRL*/;	if (ev.x == 13) ev.x = KBD_ENTER;	if (ev.x == 127) ev.x = KBD_BS;	if (ev.x >= 0 && ev.x < ' ') {		ev.x += 'A' - 1;		ev.y |= KBD_CTRL;	}	l1:	if (itrm->qlen < el) {		internal("event queue underflow");		itrm->qlen = el;	}	if (ev.x != -1) {		itrm->queue_event(itrm, (char *)&ev, sizeof(struct event));		memmove(itrm->kqueue, itrm->kqueue + el, itrm->qlen -= el);	} else {		/*printf("%d %d\n", itrm->qlen, el);fflush(stdout);*/		memmove(itrm->kqueue, itrm->kqueue + el, itrm->qlen -= el);	}	end:	if (itrm->qlen < IN_BUF_SIZE && !itrm->blocked) set_handlers(itrm->std_in, (void (*)(void *))in_kbd, NULL, (void (*)(void *))itrm->free_trm, itrm);	return el;	ret:	itrm->tm = install_timer(ESC_TIMEOUT, (void (*)(void *))kbd_timeout, itrm);	return 0;}void in_kbd(struct itrm *itrm){	int r;	if (!can_read(itrm->std_in)) return;	if (itrm->tm != -1) kill_timer(itrm->tm), itrm->tm = -1;	if (itrm->qlen >= IN_BUF_SIZE) {		set_handlers(itrm->std_in, NULL, NULL, (void (*)(void *))itrm->free_trm, itrm);		while (process_queue(itrm));		return;	}	if ((r = read(itrm->std_in, itrm->kqueue + itrm->qlen, IN_BUF_SIZE - itrm->qlen)) <= 0) {		itrm->free_trm(itrm);		return;	}	if ((itrm->qlen += r) > IN_BUF_SIZE) {		error("ERROR: too many bytes read");		itrm->qlen = IN_BUF_SIZE;	}	while (process_queue(itrm));}#if defined(GRDRV_SVGALIB) || defined(GRDRV_FB)int kbd_set_raw;void svgalib_free_trm(struct itrm *itrm){	/*debug("svgalib_free: %p", itrm);*/	if (!itrm) return;	if (kbd_set_raw) ttcsetattr(itrm->ctl_in, TCSANOW, &itrm->t);	set_handlers(itrm->std_in, NULL, NULL, NULL, NULL);	if (itrm->tm != -1) kill_timer(itrm->tm);	mem_free(itrm);	if (itrm == ditrm) ditrm = NULL;}struct itrm *handle_svgalib_keyboard(void (*queue_event)(void *, unsigned char *, int)){	struct itrm *itrm;	itrm = mem_calloc(sizeof(struct itrm));	ditrm = itrm;	itrm->queue_event = (void (*)(struct itrm *, unsigned char *, int))queue_event;	itrm->free_trm = svgalib_free_trm;	itrm->std_in = 0;	itrm->ctl_in = 0;	itrm->tm = -1;	if (kbd_set_raw) if (itrm->ctl_in >= 0) setraw(itrm->ctl_in, &itrm->t);	set_handlers(itrm->std_in, (void (*)(void *))in_kbd, NULL, (void (*)(void *))svgalib_free_trm, itrm);	/*debug("svgalib_handle: %p", itrm);*/	return itrm;}int svgalib_unblock_itrm(struct itrm *itrm){	/*debug("svgalib_unblock: %p", itrm);*/	if (!itrm) return -1;	if (kbd_set_raw) if (itrm->ctl_in >= 0) if (setraw(itrm->ctl_in, NULL)) return -1;	itrm->blocked = 0;	set_handlers(itrm->std_in, (void (*)(void *))in_kbd, NULL, (void (*)(void *))itrm->free_trm, itrm);	unblock_stdin();	return 0;}void svgalib_block_itrm(struct itrm *itrm){	/*debug("svgalib_block: %p", itrm);*/	if (!itrm) return;	itrm->blocked = 1;	block_stdin();	if (kbd_set_raw) ttcsetattr(itrm->ctl_in, TCSANOW, &itrm->t);	set_handlers(itrm->std_in, NULL, NULL, (void (*)(void *))itrm->free_trm, itrm);}#endif

⌨️ 快捷键说明

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