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

📄 keyinput.c

📁 //初始化 if(initscr() == NULL) { perror("initcurs") exit(EXIT_FAILURE) } //设置模式
💻 C
字号:
	/* File: keyinput.c */	#include <curses.h>	#include <stdlib.h>	#include <ctype.h>	int main(int argc, char *argv[])	{		WINDOW  *win;		int ch;		int w = 40, h = 10;		int curx = 10, cury = 5; 		//初始化		if(initscr() == NULL) {			perror("initcurs");			exit(EXIT_FAILURE);		}		//设置模式		cbreak();		noecho();		keypad(stdscr, TRUE);		//建立窗口		win = newwin(h, w, 3, 20);		box(win, 0, 0);		keypad(win, TRUE);		wmove(win, cury, curx);		mvaddstr(16, 1, "Press arrow keys to move the cursor within the window.\n");		mvaddstr(17, 1, "Press 'q' to quit.\n");		refresh();		wrefresh(win);		//获得输入		for(;;){			ch = wgetch(win);			if(ch == 'q') break;			if(ch == KEY_UP) {if(cury > 1)cury --;}			else if(ch == KEY_DOWN) {if(cury < h-2) cury ++;}			else if(ch == KEY_LEFT) {if(curx > 1) curx --;}			else if(ch == KEY_RIGHT){if(curx < w-2) curx ++;}			wmove(win, cury, curx);			mvprintw(20, 1, "Input Key: %s\n", keyname(ch));			refresh();		}		delwin(win);		endwin();		exit(0);	}

⌨️ 快捷键说明

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