/* * keyString * Converts keypresses to strings * * © 1993-1998 Straylight */ /*----- Licensing note ----------------------------------------------------* * * This file is part of Straylight's Steel library. * * Steel is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * Steel is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Steel. If not, write to the Free Software Foundation, * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "akbd.h" #include "msgs.h" #include "keyString.h" #include "buffer.h" #include #include /* * char *keyString(int key) * * Use * Converts a keypress as returned by the WIMP into a string suitable for * displaying to the user, for example as a keyboard shortcut. The routine * handles the following cases: * * * Function keys and Print, possibly with and/or * * Alphabetic keys with * * Note: f12 is not trapped; neither is M, since this is . * * Parameters * int key == the key pressed * * Returns * A pointer to a READ-ONLY string, or 0 if the key was invalid. */ char *keyString(int key) { return (keyString_convert(key,FALSE)); } typedef struct { int c : 8; int shift : 1; int ctrl : 1; int keypad : 1; int func : 1; } keyString__keyEntry; static keyString__keyEntry keyString__lower[]= { /* --- 0x000 - 0x00F --- */ ' ', 0,1,0,0, 'A', 0,1,0,0, 'B', 0,1,0,0, 'C', 0,1,0,0, 'D', 0,1,0,0, 'E', 0,1,0,0, 'F', 0,1,0,0, 'G', 0,1,0,0, 'H', 0,1,0,0, 'I', 0,1,0,0, 'J', 0,1,0,0, 'K', 0,1,0,0, 'L', 0,1,0,0, 'M', 0,1,0,0, 'N', 0,1,0,0, 'O', 0,1,0,0, /* --- 0x010 - 0x01F --- */ 'P', 0,1,0,0, 'Q', 0,1,0,0, 'R', 0,1,0,0, 'S', 0,1,0,0, 'T', 0,1,0,0, 'U', 0,1,0,0, 'V', 0,1,0,0, 'W', 0,1,0,0, 'X', 0,1,0,0, 'Y', 0,1,0,0, 'Z', 0,1,0,0, 0x01B, 0,0,0,0, 0x01C, 0,0,0,0, 0x01D, 0,0,0,0, 0x01E, 0,0,0,0, 0x07F, 0,1,0,0, }; static keyString__keyEntry keyString__upper[]= { /* --- 0x100 - 0x10F --- */ ' ', 1,1,0,0, 'A', 1,1,0,0, 'B', 1,1,0,0, 'C', 1,1,0,0, 'D', 1,1,0,0, 'E', 1,1,0,0, 'F', 1,1,0,0, 'G', 1,1,0,0, 'H', 1,1,0,0, 'I', 1,1,0,0, 'J', 1,1,0,0, 'K', 1,1,0,0, 'L', 1,1,0,0, 'M', 1,1,0,0, 'N', 1,1,0,0, 'O', 1,1,0,0, /* --- 0x110 - 0x11F --- */ 'P', 1,1,0,0, 'Q', 1,1,0,0, 'R', 1,1,0,0, 'S', 1,1,0,0, 'T', 1,1,0,0, 'U', 1,1,0,0, 'V', 1,1,0,0, 'W', 1,1,0,0, 'X', 1,1,0,0, 'Y', 1,1,0,0, 'Z', 1,1,0,0, 0x01B, 1,0,0,0, 0x01C, 1,0,0,0, 0x01D, 1,0,0,0, 0x01E, 1,0,0,0, 0x07F, 1,1,0,0, /* --- 0x120 - 0x12F --- */ ' ', 1,0,0,0, '/', 0,1,1,0, '*', 0,1,1,0, '#', 0,1,1,0, '-', 0,1,1,0, '+', 0,1,1,0, 0x01D, 0,1,1,0, '.', 0,1,1,0, 0, 0,0,0,0, 0, 0,0,0,0, 0, 0,0,0,0, '[', 0,1,0,0, '\\', 0,1,0,0, ']', 0,1,0,0, 0, 0,0,0,0, '-', 0,1,0,0, /* --- 0x130 - 0x13F --- */ '0', 0,1,0,0, '1', 0,1,0,0, '2', 0,1,0,0, '3', 0,1,0,0, '4', 0,1,0,0, '5', 0,1,0,0, '6', 0,1,0,0, '7', 0,1,0,0, '8', 0,1,0,0, '9', 0,1,0,0, 0, 0,0,0,0, 0x01B, 0,1,0,0, 0x01C, 0,1,0,0, 0x01D, 0,1,0,0, 0x01E, 0,1,0,0, 0, 0,0,0,0, /* --- 0x140 - 0x14F --- */ 0, 0,0,0,0, '/', 1,1,1,0, '*', 1,1,1,0, '#', 1,1,1,0, '-', 1,1,1,0, '+', 1,1,1,0, 0x01D, 1,1,1,0, '.', 1,1,1,0, 0, 0,0,0,0, 0, 0,0,0,0, 0, 0,0,0,0, '[', 1,1,0,0, '\\', 1,1,0,0, ']', 1,1,0,0, 0, 0,0,0,0, '-', 1,1,0,0, /* --- 0x150 - 0x15F --- */ '0', 1,1,0,0, '1', 1,1,0,0, '2', 1,1,0,0, '3', 1,1,0,0, '4', 1,1,0,0, '5', 1,1,0,0, '6', 1,1,0,0, '7', 1,1,0,0, '8', 1,1,0,0, '9', 1,1,0,0, 0, 0,0,0,0, 0x01B, 1,1,0,0, 0x01C, 1,1,0,0, 0x01D, 1,1,0,0, 0x01E, 1,1,0,0, 0, 0,0,0,0, /* --- 0x160 - 0x16F --- */ 0, 0,0,0,0, '/', 0,0,1,0, '*', 0,0,1,0, '#', 0,0,1,0, '-', 0,0,1,0, '+', 0,0,1,0, 0x01D, 0,0,1,0, '.', 0,0,1,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, 0,0,0,0, 0, 0,0,0,0, /* --- 0x170 - 0x17F --- */ 0, 0,0,0,0, '/', 1,0,1,0, '*', 1,0,1,0, '#', 1,0,1,0, '-', 1,0,1,0, '+', 1,0,1,0, 0x01D, 1,0,1,0, '.', 1,0,1,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, 0,0,0,0, 0x07F, 1,0,0,0, /* --- 0x180 - 0x18F --- */ 0, 0,0,0,1, 1, 0,0,0,1, 2, 0,0,0,1, 3, 0,0,0,1, 4, 0,0,0,1, 5, 0,0,0,1, 6, 0,0,0,1, 7, 0,0,0,1, 8, 0,0,0,1, 9, 0,0,0,1, 13, 0,0,0,1, 14, 0,0,0,1, 15, 0,0,0,1, 16, 0,0,0,1,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,0,0,1, 11, 1,0,0,1, 12, 1,0,0,1, 19, 1,0,0,1, 0, 0,0,0,0, 0, 0,0,0,0, /* --- 0x1E0 - 0x1EF --- */ '0', 0,1,1,0, '1', 0,1,1,0, '2', 0,1,1,0, '3', 0,1,1,0, '4', 0,1,1,0, '5', 0,1,1,0, '6', 0,1,1,0, '7', 0,1,1,0, '8', 0,1,1,0, '9', 0,1,1,0, 10, 0,1,0,1, 11, 0,1,0,1, 12, 0,1,0,1, 19, 0,1,0,1, 0, 0,0,0,0, 0, 0,0,0,0, /* --- 0x1F0 - 0x1FF --- */ '0', 1,1,1,0, '1', 1,1,1,0, '2', 1,1,1,0, '3', 1,1,1,0, '4', 1,1,1,0, '5', 1,1,1,0, '6', 1,1,1,0, '7', 1,1,1,0, '8', 1,1,1,0, '9', 1,1,1,0, 10, 1,1,0,1, 11, 1,1,0,1, 12, 1,1,0,1, 19, 1,1,0,1, 0, 0,0,0,0, 0, 0,0,0,0, }; static char *keyString__fkeys[]= { "kstrPRT:Print", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "kstrF13:Tab", "kstrF14:Copy", "kstrF15:Left", "kstrF16:Right", "kstrF17:Down", "kstrF18:Up", "kstrF19:Insert", }; static char *keyString__lowctl[]= { "kstrESC:Escape", "kstrBSP:Backspace", "kstrRET:Return", "kstrHOME:Home", }; /* * char *keyString_convert(int key,BOOL mnu) * * Use * Converts a STEEL extended keypress into a string suitable for displaying * either as a short-cut string in a dialogue box or in a menu * * Parameters * int key == the keypress to translate * BOOL mnu == TRUE to create menu shortcut string, FALSE for dbox * * Returns * A pointer to the string, or 0 */ char *keyString_convert(int key,BOOL mnu) { keyString__keyEntry ke; char base[20]; char *bp; char *buffer=buffer_find(); /* --- Make sure it's not a printable character --- */ if (key<' ') ke=keyString__lower[key]; else if (key>0x0FF) ke=keyString__upper[key-0x100]; else if (key==0x07F) { ke.c=0x07F; ke.shift=ke.ctrl=ke.keypad=ke.func=0; } else return (0); if (!ke.c && !ke.func) return (0); /* --- Get the name of the base key --- */ if (ke.func) { if (ke.c==12) return (0); /* Always let F12 through */ bp=keyString__fkeys[ke.c]; if (!bp) { sprintf(base,"%s%i",msgs_lookup("kstrF:F"),ke.c); bp=base; } else bp=msgs_lookup(bp); } else if (ke.c==0x01D && ke.keypad) { ke.keypad=0; bp=msgs_lookup("kstrENT:Enter"); } else if (ke.c>0x01A && ke.c<0x01F) bp=msgs_lookup(keyString__lowctl[ke.c-0x01B]); else if (ke.c==0x07f) bp=msgs_lookup("kstrDEL:Delete"); else if (ke.c==0x020) bp=msgs_lookup("kstrSPC:Space"); else { base[0]=ke.c; base[1]=0; bp=base; } /* --- Build the keyname in the buffer --- */ buffer[0]=0; if (ke.shift) strcat(buffer,mnu ? "\x8B" : msgs_lookup("kstrSH:Shift ")); if (ke.ctrl) strcat(buffer,mnu ? "^" : msgs_lookup("kstrCTL:Ctrl ")); if (ke.keypad) strcat(buffer,mnu ? "~" : msgs_lookup("kstrKPD:Keypad ")); strcat(buffer,bp); /* --- Well, that's it at last --- */ return (buffer); }