diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2016-03-30 13:20:29 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2016-03-30 13:20:29 +0200 |
commit | 25441348c4a28fd0821fe7a173e3c6cc166deb16 (patch) | |
tree | 6facf7c7a77fed51285d738ca6c85429c4bdf73b | |
parent | 8c315b4082bd2cc70d3df5a3d34f0aeaee17d386 (diff) | |
download | fbida-25441348c4a28fd0821fe7a173e3c6cc166deb16.tar.gz |
kbd support code
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | GNUmakefile | 9 | ||||
-rw-r--r-- | KEY.h | 398 | ||||
-rw-r--r-- | fbi.c | 47 | ||||
-rw-r--r-- | kbd.c | 171 | ||||
-rw-r--r-- | kbd.h | 9 | ||||
-rw-r--r-- | kbdtest.c | 60 |
7 files changed, 647 insertions, 48 deletions
@@ -3,6 +3,7 @@ Make.config exiftran fbi fbpdf +kbdtest ida logo.h thumbnail.cgi diff --git a/GNUmakefile b/GNUmakefile index ba9d15e..6066a09 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -16,7 +16,7 @@ all: build # what to build TARGETS := exiftran thumbnail.cgi ifeq ($(HAVE_LINUX_FB_H),yes) - TARGETS += fbi fbpdf + TARGETS += fbi fbpdf kbdtest endif ifeq ($(HAVE_MOTIF),yes) TARGETS += ida @@ -172,7 +172,7 @@ ida.o: Ida.ad.h logo.h # object files OBJS_FBI := \ - fbi.o vt.o fbtools.o drmtools.o fb-gui.o desktop.o \ + fbi.o vt.o kbd.o fbtools.o drmtools.o fb-gui.o desktop.o \ parseconfig.o fbiconfig.o \ jpegtools.o jpeg/$(JPEG_VER)/transupp.o \ dither.o filter.o op.o @@ -202,6 +202,11 @@ fbpdf: $(OBJS_FBPDF) ######################################################################## +# rules for kbdtest + +kbdtest : kbdtest.o kbd.o + +######################################################################## # general rules .PHONY: check-libjpeg build install clean distclean realclean @@ -0,0 +1,398 @@ + [ KEY_RESERVED ] = "RESERVED", + [ KEY_ESC ] = "ESC", + [ KEY_1 ] = "1", + [ KEY_2 ] = "2", + [ KEY_3 ] = "3", + [ KEY_4 ] = "4", + [ KEY_5 ] = "5", + [ KEY_6 ] = "6", + [ KEY_7 ] = "7", + [ KEY_8 ] = "8", + [ KEY_9 ] = "9", + [ KEY_0 ] = "0", + [ KEY_MINUS ] = "MINUS", + [ KEY_EQUAL ] = "EQUAL", + [ KEY_BACKSPACE ] = "BACKSPACE", + [ KEY_TAB ] = "TAB", + [ KEY_Q ] = "Q", + [ KEY_W ] = "W", + [ KEY_E ] = "E", + [ KEY_R ] = "R", + [ KEY_T ] = "T", + [ KEY_Y ] = "Y", + [ KEY_U ] = "U", + [ KEY_I ] = "I", + [ KEY_O ] = "O", + [ KEY_P ] = "P", + [ KEY_LEFTBRACE ] = "LEFTBRACE", + [ KEY_RIGHTBRACE ] = "RIGHTBRACE", + [ KEY_ENTER ] = "ENTER", + [ KEY_LEFTCTRL ] = "LEFTCTRL", + [ KEY_A ] = "A", + [ KEY_S ] = "S", + [ KEY_D ] = "D", + [ KEY_F ] = "F", + [ KEY_G ] = "G", + [ KEY_H ] = "H", + [ KEY_J ] = "J", + [ KEY_K ] = "K", + [ KEY_L ] = "L", + [ KEY_SEMICOLON ] = "SEMICOLON", + [ KEY_APOSTROPHE ] = "APOSTROPHE", + [ KEY_GRAVE ] = "GRAVE", + [ KEY_LEFTSHIFT ] = "LEFTSHIFT", + [ KEY_BACKSLASH ] = "BACKSLASH", + [ KEY_Z ] = "Z", + [ KEY_X ] = "X", + [ KEY_C ] = "C", + [ KEY_V ] = "V", + [ KEY_B ] = "B", + [ KEY_N ] = "N", + [ KEY_M ] = "M", + [ KEY_COMMA ] = "COMMA", + [ KEY_DOT ] = "DOT", + [ KEY_SLASH ] = "SLASH", + [ KEY_RIGHTSHIFT ] = "RIGHTSHIFT", + [ KEY_KPASTERISK ] = "KPASTERISK", + [ KEY_LEFTALT ] = "LEFTALT", + [ KEY_SPACE ] = "SPACE", + [ KEY_CAPSLOCK ] = "CAPSLOCK", + [ KEY_F1 ] = "F1", + [ KEY_F2 ] = "F2", + [ KEY_F3 ] = "F3", + [ KEY_F4 ] = "F4", + [ KEY_F5 ] = "F5", + [ KEY_F6 ] = "F6", + [ KEY_F7 ] = "F7", + [ KEY_F8 ] = "F8", + [ KEY_F9 ] = "F9", + [ KEY_F10 ] = "F10", + [ KEY_NUMLOCK ] = "NUMLOCK", + [ KEY_SCROLLLOCK ] = "SCROLLLOCK", + [ KEY_KP7 ] = "KP7", + [ KEY_KP8 ] = "KP8", + [ KEY_KP9 ] = "KP9", + [ KEY_KPMINUS ] = "KPMINUS", + [ KEY_KP4 ] = "KP4", + [ KEY_KP5 ] = "KP5", + [ KEY_KP6 ] = "KP6", + [ KEY_KPPLUS ] = "KPPLUS", + [ KEY_KP1 ] = "KP1", + [ KEY_KP2 ] = "KP2", + [ KEY_KP3 ] = "KP3", + [ KEY_KP0 ] = "KP0", + [ KEY_KPDOT ] = "KPDOT", + [ KEY_ZENKAKUHANKAKU ] = "ZENKAKUHANKAKU", + [ KEY_102ND ] = "102ND", + [ KEY_F11 ] = "F11", + [ KEY_F12 ] = "F12", + [ KEY_RO ] = "RO", + [ KEY_KATAKANA ] = "KATAKANA", + [ KEY_HIRAGANA ] = "HIRAGANA", + [ KEY_HENKAN ] = "HENKAN", + [ KEY_KATAKANAHIRAGANA ] = "KATAKANAHIRAGANA", + [ KEY_MUHENKAN ] = "MUHENKAN", + [ KEY_KPJPCOMMA ] = "KPJPCOMMA", + [ KEY_KPENTER ] = "KPENTER", + [ KEY_RIGHTCTRL ] = "RIGHTCTRL", + [ KEY_KPSLASH ] = "KPSLASH", + [ KEY_SYSRQ ] = "SYSRQ", + [ KEY_RIGHTALT ] = "RIGHTALT", + [ KEY_LINEFEED ] = "LINEFEED", + [ KEY_HOME ] = "HOME", + [ KEY_UP ] = "UP", + [ KEY_PAGEUP ] = "PAGEUP", + [ KEY_LEFT ] = "LEFT", + [ KEY_RIGHT ] = "RIGHT", + [ KEY_END ] = "END", + [ KEY_DOWN ] = "DOWN", + [ KEY_PAGEDOWN ] = "PAGEDOWN", + [ KEY_INSERT ] = "INSERT", + [ KEY_DELETE ] = "DELETE", + [ KEY_MACRO ] = "MACRO", + [ KEY_MUTE ] = "MUTE", + [ KEY_VOLUMEDOWN ] = "VOLUMEDOWN", + [ KEY_VOLUMEUP ] = "VOLUMEUP", + [ KEY_POWER ] = "POWER", + [ KEY_KPEQUAL ] = "KPEQUAL", + [ KEY_KPPLUSMINUS ] = "KPPLUSMINUS", + [ KEY_PAUSE ] = "PAUSE", + [ KEY_SCALE ] = "SCALE", + [ KEY_KPCOMMA ] = "KPCOMMA", + [ KEY_HANGEUL ] = "HANGEUL", + [ KEY_HANGUEL ] = "HANGUEL", + [ KEY_HANJA ] = "HANJA", + [ KEY_YEN ] = "YEN", + [ KEY_LEFTMETA ] = "LEFTMETA", + [ KEY_RIGHTMETA ] = "RIGHTMETA", + [ KEY_COMPOSE ] = "COMPOSE", + [ KEY_STOP ] = "STOP", + [ KEY_AGAIN ] = "AGAIN", + [ KEY_PROPS ] = "PROPS", + [ KEY_UNDO ] = "UNDO", + [ KEY_FRONT ] = "FRONT", + [ KEY_COPY ] = "COPY", + [ KEY_OPEN ] = "OPEN", + [ KEY_PASTE ] = "PASTE", + [ KEY_FIND ] = "FIND", + [ KEY_CUT ] = "CUT", + [ KEY_HELP ] = "HELP", + [ KEY_MENU ] = "MENU", + [ KEY_CALC ] = "CALC", + [ KEY_SETUP ] = "SETUP", + [ KEY_SLEEP ] = "SLEEP", + [ KEY_WAKEUP ] = "WAKEUP", + [ KEY_FILE ] = "FILE", + [ KEY_SENDFILE ] = "SENDFILE", + [ KEY_DELETEFILE ] = "DELETEFILE", + [ KEY_XFER ] = "XFER", + [ KEY_PROG1 ] = "PROG1", + [ KEY_PROG2 ] = "PROG2", + [ KEY_WWW ] = "WWW", + [ KEY_MSDOS ] = "MSDOS", + [ KEY_COFFEE ] = "COFFEE", + [ KEY_SCREENLOCK ] = "SCREENLOCK", + [ KEY_DIRECTION ] = "DIRECTION", + [ KEY_CYCLEWINDOWS ] = "CYCLEWINDOWS", + [ KEY_MAIL ] = "MAIL", + [ KEY_BOOKMARKS ] = "BOOKMARKS", + [ KEY_COMPUTER ] = "COMPUTER", + [ KEY_BACK ] = "BACK", + [ KEY_FORWARD ] = "FORWARD", + [ KEY_CLOSECD ] = "CLOSECD", + [ KEY_EJECTCD ] = "EJECTCD", + [ KEY_EJECTCLOSECD ] = "EJECTCLOSECD", + [ KEY_NEXTSONG ] = "NEXTSONG", + [ KEY_PLAYPAUSE ] = "PLAYPAUSE", + [ KEY_PREVIOUSSONG ] = "PREVIOUSSONG", + [ KEY_STOPCD ] = "STOPCD", + [ KEY_RECORD ] = "RECORD", + [ KEY_REWIND ] = "REWIND", + [ KEY_PHONE ] = "PHONE", + [ KEY_ISO ] = "ISO", + [ KEY_CONFIG ] = "CONFIG", + [ KEY_HOMEPAGE ] = "HOMEPAGE", + [ KEY_REFRESH ] = "REFRESH", + [ KEY_EXIT ] = "EXIT", + [ KEY_MOVE ] = "MOVE", + [ KEY_EDIT ] = "EDIT", + [ KEY_SCROLLUP ] = "SCROLLUP", + [ KEY_SCROLLDOWN ] = "SCROLLDOWN", + [ KEY_KPLEFTPAREN ] = "KPLEFTPAREN", + [ KEY_KPRIGHTPAREN ] = "KPRIGHTPAREN", + [ KEY_NEW ] = "NEW", + [ KEY_REDO ] = "REDO", + [ KEY_F13 ] = "F13", + [ KEY_F14 ] = "F14", + [ KEY_F15 ] = "F15", + [ KEY_F16 ] = "F16", + [ KEY_F17 ] = "F17", + [ KEY_F18 ] = "F18", + [ KEY_F19 ] = "F19", + [ KEY_F20 ] = "F20", + [ KEY_F21 ] = "F21", + [ KEY_F22 ] = "F22", + [ KEY_F23 ] = "F23", + [ KEY_F24 ] = "F24", + [ KEY_PLAYCD ] = "PLAYCD", + [ KEY_PAUSECD ] = "PAUSECD", + [ KEY_PROG3 ] = "PROG3", + [ KEY_PROG4 ] = "PROG4", + [ KEY_DASHBOARD ] = "DASHBOARD", + [ KEY_SUSPEND ] = "SUSPEND", + [ KEY_CLOSE ] = "CLOSE", + [ KEY_PLAY ] = "PLAY", + [ KEY_FASTFORWARD ] = "FASTFORWARD", + [ KEY_BASSBOOST ] = "BASSBOOST", + [ KEY_PRINT ] = "PRINT", + [ KEY_HP ] = "HP", + [ KEY_CAMERA ] = "CAMERA", + [ KEY_SOUND ] = "SOUND", + [ KEY_QUESTION ] = "QUESTION", + [ KEY_EMAIL ] = "EMAIL", + [ KEY_CHAT ] = "CHAT", + [ KEY_SEARCH ] = "SEARCH", + [ KEY_CONNECT ] = "CONNECT", + [ KEY_FINANCE ] = "FINANCE", + [ KEY_SPORT ] = "SPORT", + [ KEY_SHOP ] = "SHOP", + [ KEY_ALTERASE ] = "ALTERASE", + [ KEY_CANCEL ] = "CANCEL", + [ KEY_BRIGHTNESSDOWN ] = "BRIGHTNESSDOWN", + [ KEY_BRIGHTNESSUP ] = "BRIGHTNESSUP", + [ KEY_MEDIA ] = "MEDIA", + [ KEY_SWITCHVIDEOMODE ] = "SWITCHVIDEOMODE", + [ KEY_KBDILLUMTOGGLE ] = "KBDILLUMTOGGLE", + [ KEY_KBDILLUMDOWN ] = "KBDILLUMDOWN", + [ KEY_KBDILLUMUP ] = "KBDILLUMUP", + [ KEY_SEND ] = "SEND", + [ KEY_REPLY ] = "REPLY", + [ KEY_FORWARDMAIL ] = "FORWARDMAIL", + [ KEY_SAVE ] = "SAVE", + [ KEY_DOCUMENTS ] = "DOCUMENTS", + [ KEY_BATTERY ] = "BATTERY", + [ KEY_BLUETOOTH ] = "BLUETOOTH", + [ KEY_WLAN ] = "WLAN", + [ KEY_UWB ] = "UWB", + [ KEY_UNKNOWN ] = "UNKNOWN", + [ KEY_VIDEO_NEXT ] = "VIDEO_NEXT", + [ KEY_VIDEO_PREV ] = "VIDEO_PREV", + [ KEY_BRIGHTNESS_CYCLE ] = "BRIGHTNESS_CYCLE", + [ KEY_BRIGHTNESS_ZERO ] = "BRIGHTNESS_ZERO", + [ KEY_DISPLAY_OFF ] = "DISPLAY_OFF", + [ KEY_WIMAX ] = "WIMAX", + [ KEY_RFKILL ] = "RFKILL", + [ KEY_MICMUTE ] = "MICMUTE", + [ KEY_OK ] = "OK", + [ KEY_SELECT ] = "SELECT", + [ KEY_GOTO ] = "GOTO", + [ KEY_CLEAR ] = "CLEAR", + [ KEY_POWER2 ] = "POWER2", + [ KEY_OPTION ] = "OPTION", + [ KEY_INFO ] = "INFO", + [ KEY_TIME ] = "TIME", + [ KEY_VENDOR ] = "VENDOR", + [ KEY_ARCHIVE ] = "ARCHIVE", + [ KEY_PROGRAM ] = "PROGRAM", + [ KEY_CHANNEL ] = "CHANNEL", + [ KEY_FAVORITES ] = "FAVORITES", + [ KEY_EPG ] = "EPG", + [ KEY_PVR ] = "PVR", + [ KEY_MHP ] = "MHP", + [ KEY_LANGUAGE ] = "LANGUAGE", + [ KEY_TITLE ] = "TITLE", + [ KEY_SUBTITLE ] = "SUBTITLE", + [ KEY_ANGLE ] = "ANGLE", + [ KEY_ZOOM ] = "ZOOM", + [ KEY_MODE ] = "MODE", + [ KEY_KEYBOARD ] = "KEYBOARD", + [ KEY_SCREEN ] = "SCREEN", + [ KEY_PC ] = "PC", + [ KEY_TV ] = "TV", + [ KEY_TV2 ] = "TV2", + [ KEY_VCR ] = "VCR", + [ KEY_VCR2 ] = "VCR2", + [ KEY_SAT ] = "SAT", + [ KEY_SAT2 ] = "SAT2", + [ KEY_CD ] = "CD", + [ KEY_TAPE ] = "TAPE", + [ KEY_RADIO ] = "RADIO", + [ KEY_TUNER ] = "TUNER", + [ KEY_PLAYER ] = "PLAYER", + [ KEY_TEXT ] = "TEXT", + [ KEY_DVD ] = "DVD", + [ KEY_AUX ] = "AUX", + [ KEY_MP3 ] = "MP3", + [ KEY_AUDIO ] = "AUDIO", + [ KEY_VIDEO ] = "VIDEO", + [ KEY_DIRECTORY ] = "DIRECTORY", + [ KEY_LIST ] = "LIST", + [ KEY_MEMO ] = "MEMO", + [ KEY_CALENDAR ] = "CALENDAR", + [ KEY_RED ] = "RED", + [ KEY_GREEN ] = "GREEN", + [ KEY_YELLOW ] = "YELLOW", + [ KEY_BLUE ] = "BLUE", + [ KEY_CHANNELUP ] = "CHANNELUP", + [ KEY_CHANNELDOWN ] = "CHANNELDOWN", + [ KEY_FIRST ] = "FIRST", + [ KEY_LAST ] = "LAST", + [ KEY_AB ] = "AB", + [ KEY_NEXT ] = "NEXT", + [ KEY_RESTART ] = "RESTART", + [ KEY_SLOW ] = "SLOW", + [ KEY_SHUFFLE ] = "SHUFFLE", + [ KEY_BREAK ] = "BREAK", + [ KEY_PREVIOUS ] = "PREVIOUS", + [ KEY_DIGITS ] = "DIGITS", + [ KEY_TEEN ] = "TEEN", + [ KEY_TWEN ] = "TWEN", + [ KEY_VIDEOPHONE ] = "VIDEOPHONE", + [ KEY_GAMES ] = "GAMES", + [ KEY_ZOOMIN ] = "ZOOMIN", + [ KEY_ZOOMOUT ] = "ZOOMOUT", + [ KEY_ZOOMRESET ] = "ZOOMRESET", + [ KEY_WORDPROCESSOR ] = "WORDPROCESSOR", + [ KEY_EDITOR ] = "EDITOR", + [ KEY_SPREADSHEET ] = "SPREADSHEET", + [ KEY_GRAPHICSEDITOR ] = "GRAPHICSEDITOR", + [ KEY_PRESENTATION ] = "PRESENTATION", + [ KEY_DATABASE ] = "DATABASE", + [ KEY_NEWS ] = "NEWS", + [ KEY_VOICEMAIL ] = "VOICEMAIL", + [ KEY_ADDRESSBOOK ] = "ADDRESSBOOK", + [ KEY_MESSENGER ] = "MESSENGER", + [ KEY_DISPLAYTOGGLE ] = "DISPLAYTOGGLE", + [ KEY_SPELLCHECK ] = "SPELLCHECK", + [ KEY_LOGOFF ] = "LOGOFF", + [ KEY_DOLLAR ] = "DOLLAR", + [ KEY_EURO ] = "EURO", + [ KEY_FRAMEBACK ] = "FRAMEBACK", + [ KEY_FRAMEFORWARD ] = "FRAMEFORWARD", + [ KEY_CONTEXT_MENU ] = "CONTEXT_MENU", + [ KEY_MEDIA_REPEAT ] = "MEDIA_REPEAT", + [ KEY_10CHANNELSUP ] = "10CHANNELSUP", + [ KEY_10CHANNELSDOWN ] = "10CHANNELSDOWN", + [ KEY_IMAGES ] = "IMAGES", + [ KEY_DEL_EOL ] = "DEL_EOL", + [ KEY_DEL_EOS ] = "DEL_EOS", + [ KEY_INS_LINE ] = "INS_LINE", + [ KEY_DEL_LINE ] = "DEL_LINE", + [ KEY_FN ] = "FN", + [ KEY_FN_ESC ] = "FN_ESC", + [ KEY_FN_F1 ] = "FN_F1", + [ KEY_FN_F2 ] = "FN_F2", + [ KEY_FN_F3 ] = "FN_F3", + [ KEY_FN_F4 ] = "FN_F4", + [ KEY_FN_F5 ] = "FN_F5", + [ KEY_FN_F6 ] = "FN_F6", + [ KEY_FN_F7 ] = "FN_F7", + [ KEY_FN_F8 ] = "FN_F8", + [ KEY_FN_F9 ] = "FN_F9", + [ KEY_FN_F10 ] = "FN_F10", + [ KEY_FN_F11 ] = "FN_F11", + [ KEY_FN_F12 ] = "FN_F12", + [ KEY_FN_1 ] = "FN_1", + [ KEY_FN_2 ] = "FN_2", + [ KEY_FN_D ] = "FN_D", + [ KEY_FN_E ] = "FN_E", + [ KEY_FN_F ] = "FN_F", + [ KEY_FN_S ] = "FN_S", + [ KEY_FN_B ] = "FN_B", + [ KEY_BRL_DOT1 ] = "BRL_DOT1", + [ KEY_BRL_DOT2 ] = "BRL_DOT2", + [ KEY_BRL_DOT3 ] = "BRL_DOT3", + [ KEY_BRL_DOT4 ] = "BRL_DOT4", + [ KEY_BRL_DOT5 ] = "BRL_DOT5", + [ KEY_BRL_DOT6 ] = "BRL_DOT6", + [ KEY_BRL_DOT7 ] = "BRL_DOT7", + [ KEY_BRL_DOT8 ] = "BRL_DOT8", + [ KEY_BRL_DOT9 ] = "BRL_DOT9", + [ KEY_BRL_DOT10 ] = "BRL_DOT10", + [ KEY_NUMERIC_0 ] = "NUMERIC_0", + [ KEY_NUMERIC_1 ] = "NUMERIC_1", + [ KEY_NUMERIC_2 ] = "NUMERIC_2", + [ KEY_NUMERIC_3 ] = "NUMERIC_3", + [ KEY_NUMERIC_4 ] = "NUMERIC_4", + [ KEY_NUMERIC_5 ] = "NUMERIC_5", + [ KEY_NUMERIC_6 ] = "NUMERIC_6", + [ KEY_NUMERIC_7 ] = "NUMERIC_7", + [ KEY_NUMERIC_8 ] = "NUMERIC_8", + [ KEY_NUMERIC_9 ] = "NUMERIC_9", + [ KEY_NUMERIC_STAR ] = "NUMERIC_STAR", + [ KEY_NUMERIC_POUND ] = "NUMERIC_POUND", + [ KEY_CAMERA_FOCUS ] = "CAMERA_FOCUS", + [ KEY_WPS_BUTTON ] = "WPS_BUTTON", + [ KEY_TOUCHPAD_TOGGLE ] = "TOUCHPAD_TOGGLE", + [ KEY_TOUCHPAD_ON ] = "TOUCHPAD_ON", + [ KEY_TOUCHPAD_OFF ] = "TOUCHPAD_OFF", + [ KEY_CAMERA_ZOOMIN ] = "CAMERA_ZOOMIN", + [ KEY_CAMERA_ZOOMOUT ] = "CAMERA_ZOOMOUT", + [ KEY_CAMERA_UP ] = "CAMERA_UP", + [ KEY_CAMERA_DOWN ] = "CAMERA_DOWN", + [ KEY_CAMERA_LEFT ] = "CAMERA_LEFT", + [ KEY_CAMERA_RIGHT ] = "CAMERA_RIGHT", + [ KEY_ATTENDANT_ON ] = "ATTENDANT_ON", + [ KEY_ATTENDANT_OFF ] = "ATTENDANT_OFF", + [ KEY_ATTENDANT_TOGGLE ] = "ATTENDANT_TOGGLE", + [ KEY_LIGHTS_TOGGLE ] = "LIGHTS_TOGGLE", @@ -38,6 +38,7 @@ #include "readers.h" #include "vt.h" +#include "kbd.h" #include "fbtools.h" #include "drmtools.h" #include "fb-gui.h" @@ -566,49 +567,6 @@ static void show_help(void) /* ---------------------------------------------------------------------- */ -struct termios saved_attributes; -int saved_fl; - -static void -tty_raw(void) -{ - struct termios tattr; - - fcntl(STDIN_FILENO, F_GETFL, &saved_fl); - tcgetattr (0, &saved_attributes); - - fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); - memcpy(&tattr,&saved_attributes,sizeof(struct termios)); - tattr.c_lflag &= ~(ICANON|ECHO); - tattr.c_cc[VMIN] = 1; - tattr.c_cc[VTIME] = 0; - tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr); -} - -static void -tty_restore(void) -{ - fcntl(STDIN_FILENO, F_SETFL, saved_fl); - tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes); -} - -/* testing: find key codes */ -static void debug_key(char *key) -{ - char linebuffer[128]; - int i,len; - - len = sprintf(linebuffer,"key: "); - for (i = 0; key[i] != '\0'; i++) - len += snprintf(linebuffer+len, sizeof(linebuffer)-len, - "%s%c", - key[i] < 0x20 ? "^" : "", - key[i] < 0x20 ? key[i] + 0x40 : key[i]); - status_update(linebuffer, NULL); -} - -/* ---------------------------------------------------------------------- */ - static void free_image(struct ida_image *img) { if (img) { @@ -1193,9 +1151,6 @@ static char edit_line(struct ida_image *img, char *line, int max) len++; line[len] = 0; - } else if (0 /* debug */) { - debug_key(key); - sleep(1); } } while (1); } @@ -0,0 +1,171 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <inttypes.h> +#include <time.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> +#include <termios.h> + +#include "kbd.h" + +/* ---------------------------------------------------------------------- */ + +struct termctrl { + const char *seq; + uint32_t code; + uint32_t mod; +}; + +static struct termctrl termctrl[] = { + { .seq = "a", .code = KEY_A }, + { .seq = "b", .code = KEY_B }, + { .seq = "c", .code = KEY_C }, + { .seq = "d", .code = KEY_D }, + { .seq = "e", .code = KEY_E }, + { .seq = "f", .code = KEY_F }, + { .seq = "g", .code = KEY_G }, + { .seq = "h", .code = KEY_H }, + { .seq = "i", .code = KEY_I }, + { .seq = "j", .code = KEY_J }, + { .seq = "k", .code = KEY_K }, + { .seq = "l", .code = KEY_L }, + { .seq = "m", .code = KEY_M }, + { .seq = "n", .code = KEY_N }, + { .seq = "o", .code = KEY_O }, + { .seq = "p", .code = KEY_P }, + { .seq = "q", .code = KEY_Q }, + { .seq = "r", .code = KEY_R }, + { .seq = "s", .code = KEY_S }, + { .seq = "t", .code = KEY_T }, + { .seq = "u", .code = KEY_U }, + { .seq = "v", .code = KEY_V }, + { .seq = "w", .code = KEY_W }, + { .seq = "x", .code = KEY_X }, + { .seq = "y", .code = KEY_Y }, + { .seq = "z", .code = KEY_Z }, + + { .seq = "A", .code = KEY_A, .mod = KEY_MOD_SHIFT }, + { .seq = "B", .code = KEY_B, .mod = KEY_MOD_SHIFT }, + { .seq = "C", .code = KEY_C, .mod = KEY_MOD_SHIFT }, + { .seq = "D", .code = KEY_D, .mod = KEY_MOD_SHIFT }, + { .seq = "E", .code = KEY_E, .mod = KEY_MOD_SHIFT }, + { .seq = "F", .code = KEY_F, .mod = KEY_MOD_SHIFT }, + { .seq = "G", .code = KEY_G, .mod = KEY_MOD_SHIFT }, + { .seq = "H", .code = KEY_H, .mod = KEY_MOD_SHIFT }, + { .seq = "I", .code = KEY_I, .mod = KEY_MOD_SHIFT }, + { .seq = "J", .code = KEY_J, .mod = KEY_MOD_SHIFT }, + { .seq = "K", .code = KEY_K, .mod = KEY_MOD_SHIFT }, + { .seq = "L", .code = KEY_L, .mod = KEY_MOD_SHIFT }, + { .seq = "M", .code = KEY_M, .mod = KEY_MOD_SHIFT }, + { .seq = "N", .code = KEY_N, .mod = KEY_MOD_SHIFT }, + { .seq = "O", .code = KEY_O, .mod = KEY_MOD_SHIFT }, + { .seq = "P", .code = KEY_P, .mod = KEY_MOD_SHIFT }, + { .seq = "Q", .code = KEY_Q, .mod = KEY_MOD_SHIFT }, + { .seq = "R", .code = KEY_R, .mod = KEY_MOD_SHIFT }, + { .seq = "S", .code = KEY_S, .mod = KEY_MOD_SHIFT }, + { .seq = "T", .code = KEY_T, .mod = KEY_MOD_SHIFT }, + { .seq = "U", .code = KEY_U, .mod = KEY_MOD_SHIFT }, + { .seq = "V", .code = KEY_V, .mod = KEY_MOD_SHIFT }, + { .seq = "W", .code = KEY_W, .mod = KEY_MOD_SHIFT }, + { .seq = "X", .code = KEY_X, .mod = KEY_MOD_SHIFT }, + { .seq = "Y", .code = KEY_Y, .mod = KEY_MOD_SHIFT }, + { .seq = "Z", .code = KEY_Z, .mod = KEY_MOD_SHIFT }, + + { .seq = "0", .code = KEY_0, }, + { .seq = "1", .code = KEY_1, }, + { .seq = "2", .code = KEY_2, }, + { .seq = "3", .code = KEY_3, }, + { .seq = "4", .code = KEY_4, }, + { .seq = "5", .code = KEY_5, }, + { .seq = "6", .code = KEY_6, }, + { .seq = "7", .code = KEY_7, }, + { .seq = "8", .code = KEY_8, }, + { .seq = "9", .code = KEY_9, }, + + { .seq = "\x1b[A", .code = KEY_UP }, + { .seq = "\x1b[B", .code = KEY_DOWN }, + { .seq = "\x1b[C", .code = KEY_RIGHT }, + { .seq = "\x1b[D", .code = KEY_LEFT }, + { .seq = "\x1b[F", .code = KEY_END }, + { .seq = "\x1b[H", .code = KEY_HOME }, + + { .seq = "\x1b[1~", .code = KEY_HOME }, + { .seq = "\x1b[2~", .code = KEY_INSERT }, + { .seq = "\x1b[3~", .code = KEY_DELETE }, + { .seq = "\x1b[4~", .code = KEY_END }, + { .seq = "\x1b[5~", .code = KEY_PAGEUP }, + { .seq = "\x1b[6~", .code = KEY_PAGEDOWN }, + + { .seq = "\x01", .code = KEY_A, .mod = KEY_MOD_CTRL }, + { .seq = "\x02", .code = KEY_B, .mod = KEY_MOD_CTRL }, + { .seq = "\x03", .code = KEY_C, .mod = KEY_MOD_CTRL }, + { .seq = "\x04", .code = KEY_D, .mod = KEY_MOD_CTRL }, + { .seq = "\x05", .code = KEY_E, .mod = KEY_MOD_CTRL }, + { .seq = "\x06", .code = KEY_F, .mod = KEY_MOD_CTRL }, + { .seq = "\x07", .code = KEY_G, .mod = KEY_MOD_CTRL }, + { .seq = "\x08", .code = KEY_H, .mod = KEY_MOD_CTRL }, + { .seq = "\x09", .code = KEY_I, .mod = KEY_MOD_CTRL }, + { .seq = "\x0a", .code = KEY_J, .mod = KEY_MOD_CTRL }, + { .seq = "\x0b", .code = KEY_K, .mod = KEY_MOD_CTRL }, + { .seq = "\x0c", .code = KEY_L, .mod = KEY_MOD_CTRL }, + { .seq = "\x0d", .code = KEY_M, .mod = KEY_MOD_CTRL }, + { .seq = "\x0e", .code = KEY_N, .mod = KEY_MOD_CTRL }, + { .seq = "\x0f", .code = KEY_O, .mod = KEY_MOD_CTRL }, + { .seq = "\x10", .code = KEY_P, .mod = KEY_MOD_CTRL }, + { .seq = "\x11", .code = KEY_Q, .mod = KEY_MOD_CTRL }, + { .seq = "\x12", .code = KEY_R, .mod = KEY_MOD_CTRL }, + { .seq = "\x13", .code = KEY_S, .mod = KEY_MOD_CTRL }, + { .seq = "\x14", .code = KEY_T, .mod = KEY_MOD_CTRL }, + { .seq = "\x15", .code = KEY_U, .mod = KEY_MOD_CTRL }, + { .seq = "\x16", .code = KEY_V, .mod = KEY_MOD_CTRL }, + { .seq = "\x17", .code = KEY_W, .mod = KEY_MOD_CTRL }, + { .seq = "\x18", .code = KEY_X, .mod = KEY_MOD_CTRL }, + { .seq = "\x19", .code = KEY_Y, .mod = KEY_MOD_CTRL }, + { .seq = "\x1a", .code = KEY_Z, .mod = KEY_MOD_CTRL }, + { .seq = "\x1b", .code = KEY_ESC }, + + { /* EOF */ } +}; + +uint32_t kbd_parse(const char *key, uint32_t *mod) +{ + int i; + + for (i = 0; termctrl[i].seq != NULL; i++) { + if (strcmp(key, termctrl[i].seq) == 0) { + *mod = termctrl[i].mod; + return termctrl[i].code; + } + } + *mod = 0; + return KEY_RESERVED; +} + +/* ---------------------------------------------------------------------- */ + +struct termios saved_attributes; +int saved_fl; + +void tty_raw(void) +{ + struct termios tattr; + + fcntl(STDIN_FILENO, F_GETFL, &saved_fl); + tcgetattr (0, &saved_attributes); + + fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK); + memcpy(&tattr,&saved_attributes,sizeof(struct termios)); + tattr.c_lflag &= ~(ICANON|ECHO); + tattr.c_cc[VMIN] = 1; + tattr.c_cc[VTIME] = 0; + tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr); +} + +void tty_restore(void) +{ + fcntl(STDIN_FILENO, F_SETFL, saved_fl); + tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes); +} @@ -0,0 +1,9 @@ +#include <linux/input.h> + +#define KEY_MOD_SHIFT (1 << 0) +#define KEY_MOD_CTRL (1 << 1) + +uint32_t kbd_parse(const char *key, uint32_t *mod); + +void tty_raw(void); +void tty_restore(void); diff --git a/kbdtest.c b/kbdtest.c new file mode 100644 index 0000000..849e5e2 --- /dev/null +++ b/kbdtest.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <inttypes.h> +#include <time.h> +#include <fcntl.h> +#include <ctype.h> +#include <errno.h> +#include <termios.h> + +#include "kbd.h" + +/* ---------------------------------------------------------------------- */ + +static const char *keyname[KEY_CNT] = { +#include "KEY.h" +}; + +int main(int argc, char *argv[]) +{ + struct timeval limit; + uint32_t code, mod; + char key[32]; + fd_set set; + int rc,i; + + tty_raw(); + + for (;;) { + FD_ZERO(&set); + FD_SET(0, &set); + limit.tv_sec = 10; + limit.tv_usec = 0; + rc = select(1, &set, NULL, NULL, &limit); + if (0 == rc || !FD_ISSET(0,&set)) + break; + + memset(key, 0, sizeof(key)); + rc = read(0, key, sizeof(key)-1); + if (rc < 1) { + /* EOF */ + break; + } + + code = kbd_parse(key, &mod); + fprintf(stderr, "key: \""); + for (i = 0; key[i] != 0; i++) { + fprintf(stderr, "%c", isprint(key[i]) ? key[i] : '.'); + } + fprintf(stderr, "\" -> %s", keyname[code]); + if (mod & KEY_MOD_SHIFT) + fprintf(stderr, " +shift"); + if (mod & KEY_MOD_CTRL) + fprintf(stderr, " +ctrl"); + fprintf(stderr, "\n"); + } + tty_restore(); + return 0; +} |