3 * Converts keypresses to strings
5 * © 1993-1998 Straylight
8 /*----- Licensing note ----------------------------------------------------*
10 * This file is part of Straylight's Steel library.
12 * Steel is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
17 * Steel is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Steel. If not, write to the Free Software Foundation,
24 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 #include "keyString.h"
35 * char *keyString(int key)
38 * Converts a keypress as returned by the WIMP into a string suitable for
39 * displaying to the user, for example as a keyboard shortcut. The routine
40 * handles the following cases:
42 * * Function keys and Print, possibly with <Shift> and/or <Ctrl>
43 * * Alphabetic keys with <Ctrl>
45 * Note: f12 is not trapped; neither is <Ctrl> M, since this is <Return>.
48 * int key == the key pressed
51 * A pointer to a READ-ONLY string, or 0 if the key was invalid.
54 char *keyString(int key)
56 return (keyString_convert(key,FALSE));
69 static keyString__keyEntry keyString__lower[]=
71 /* --- 0x000 - 0x00F --- */
90 /* --- 0x010 - 0x01F --- */
110 static keyString__keyEntry keyString__upper[]=
112 /* --- 0x100 - 0x10F --- */
131 /* --- 0x110 - 0x11F --- */
150 /* --- 0x120 - 0x12F --- */
169 /* --- 0x130 - 0x13F --- */
188 /* --- 0x140 - 0x14F --- */
207 /* --- 0x150 - 0x15F --- */
226 /* --- 0x160 - 0x16F --- */
245 /* --- 0x170 - 0x17F --- */
264 /* --- 0x180 - 0x18F --- */
283 /* --- 0x190 - 0x19F --- */
302 /* --- 0x1A0 - 0x1AF --- */
321 /* --- 0x1B0 - 0x1BF --- */
340 /* --- 0x1C0 - 0x1CF --- */
359 /* --- 0x1D0 - 0x1DF --- */
378 /* --- 0x1E0 - 0x1EF --- */
397 /* --- 0x1F0 - 0x1FF --- */
417 static char *keyString__fkeys[]=
441 static char *keyString__lowctl[]=
450 * char *keyString_convert(int key,BOOL mnu)
453 * Converts a STEEL extended keypress into a string suitable for displaying
454 * either as a short-cut string in a dialogue box or in a menu
457 * int key == the keypress to translate
458 * BOOL mnu == TRUE to create menu shortcut string, FALSE for dbox
461 * A pointer to the string, or 0
464 char *keyString_convert(int key,BOOL mnu)
466 keyString__keyEntry ke;
469 char *buffer=buffer_find();
471 /* --- Make sure it's not a printable character --- */
474 ke=keyString__lower[key];
476 ke=keyString__upper[key-0x100];
480 ke.shift=ke.ctrl=ke.keypad=ke.func=0;
484 if (!ke.c && !ke.func)
487 /* --- Get the name of the base key --- */
492 return (0); /* Always let F12 through */
493 bp=keyString__fkeys[ke.c];
496 sprintf(base,"%s%i",msgs_lookup("kstrF:F"),ke.c);
502 else if (ke.c==0x01D && ke.keypad)
505 bp=msgs_lookup("kstrENT:Enter");
507 else if (ke.c>0x01A && ke.c<0x01F)
508 bp=msgs_lookup(keyString__lowctl[ke.c-0x01B]);
509 else if (ke.c==0x07f)
510 bp=msgs_lookup("kstrDEL:Delete");
511 else if (ke.c==0x020)
512 bp=msgs_lookup("kstrSPC:Space");
520 /* --- Build the keyname in the buffer --- */
524 strcat(buffer,mnu ? "\x8B" : msgs_lookup("kstrSH:Shift "));
526 strcat(buffer,mnu ? "^" : msgs_lookup("kstrCTL:Ctrl "));
528 strcat(buffer,mnu ? "~" : msgs_lookup("kstrKPD:Keypad "));
531 /* --- Well, that's it at last --- */