source: abuse/trunk/src/imlib/keys.cpp @ 56

Last change on this file since 56 was 56, checked in by Sam Hocevar, 15 years ago
  • Add licensing terms to most C / C++ files (Ref #5).
File size: 3.6 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *
5 *  This software was released into the Public Domain. As with most public
6 *  domain software, no warranty is made or implied by Crack dot Com or
7 *  Jonathan Clark.
8 */
9
10#include "config.h"
11
12#include <string.h>
13#include <ctype.h>
14
15#include "keys.hpp"
16
17char const *jk_key_names[]=
18{
19    "Up Arrow","Down Arrow","Left Arrow","Right Arrow",
20    "Left Ctrl","Right Ctrl","Left Alt","Right Alt",
21    "Left Shift","Right Shift","Caps Lock","Num Lock",
22    "Home","End","Del","F1","F2","F3","F4","F5","F6",
23    "F7","F8","F9","F10","Insert","PageUp","PageDown","Command"
24};
25
26void key_name(int key, char *buffer)
27{
28    //static char sing[2];
29    if( key > 255 && key <= JK_MAX_KEY )
30        strcpy(buffer,jk_key_names[key-256]);
31    else if( key == JK_BACKSPACE )
32        strcpy(buffer,"Backspace");
33    else if( key == JK_TAB )
34        strcpy(buffer,"Tab");
35    else if( key == JK_ENTER )
36        strcpy(buffer,"Enter");
37    else if( key == JK_ESC )
38        strcpy(buffer,"Esc");
39    else if( key == JK_SPACE )
40        strcpy( buffer, "Space" );
41    else if( isprint(key) )
42    {
43        buffer[0] = key;
44        buffer[1] = 0;
45    }
46    else
47    {
48        buffer[0] = 0;
49    }
50}
51
52int key_value(char const *buffer)
53{
54    if( strcasecmp( buffer, "Backspace" ) == 0 )
55        return JK_BACKSPACE;
56    if( strcasecmp( buffer, "Tab" ) == 0 )
57        return JK_TAB;
58    if( strcasecmp( buffer, "Enter" ) == 0 )
59        return JK_ENTER;
60    if( strcasecmp( buffer, "ESC" ) == 0 )
61        return JK_ESC;
62    if( strcasecmp( buffer, "Space" ) == 0 )
63        return JK_SPACE;
64    if( strcasecmp( buffer, "Up" ) == 0 )
65        return JK_UP;
66    if( strcasecmp( buffer, "Down" ) == 0 )
67        return JK_DOWN;
68    if( strcasecmp( buffer, "Left" ) == 0 )
69        return JK_LEFT;
70    if( strcasecmp( buffer, "Right" ) == 0 )
71        return JK_RIGHT;
72    if( strcasecmp( buffer, "CTRL_L" ) == 0 )
73        return JK_CTRL_L;
74    if( strcasecmp( buffer, "CTRL_R" ) == 0 )
75        return JK_CTRL_R;
76    if( strcasecmp( buffer, "ALT_L" ) == 0 )
77        return JK_ALT_L;
78    if( strcasecmp( buffer, "ALT_R" ) == 0 )
79        return JK_ALT_R;
80    if( strcasecmp( buffer, "SHIFT_L" ) == 0 )
81        return JK_SHIFT_L;
82    if( strcasecmp( buffer, "SHIFT_R" ) == 0 )
83        return JK_SHIFT_R;
84    if( strcasecmp( buffer, "Caps" ) == 0 )
85        return JK_CAPS;
86    if( strcasecmp( buffer, "Num_Lock" ) == 0 )
87        return JK_NUM_LOCK;
88    if( strcasecmp( buffer, "Home" ) == 0 )
89        return JK_HOME;
90    if( strcasecmp( buffer, "End" ) == 0 )
91        return JK_END;
92    if( strcasecmp( buffer, "Del" ) == 0 )
93        return JK_DEL;
94    if( strcasecmp( buffer, "F1" ) == 0 )
95        return JK_F1;
96    if( strcasecmp( buffer, "F2" ) == 0 )
97        return JK_F2;
98    if( strcasecmp( buffer, "F3" ) == 0 )
99        return JK_F3;
100    if( strcasecmp( buffer, "F4" ) == 0 )
101        return JK_F4;
102    if( strcasecmp( buffer, "F5" ) == 0 )
103        return JK_F5;
104    if( strcasecmp( buffer, "F6" ) == 0 )
105        return JK_F6;
106    if( strcasecmp( buffer, "F7" ) == 0 )
107        return JK_F7;
108    if( strcasecmp( buffer, "F8" ) == 0 )
109        return JK_F8;
110    if( strcasecmp( buffer, "F9" ) == 0 )
111        return JK_F9;
112    if( strcasecmp( buffer, "F10" ) == 0 )
113        return JK_F10;
114    if( strcasecmp( buffer, "Insert" ) == 0 )
115        return JK_INSERT;
116    if( strcasecmp( buffer, "PageUp" ) == 0 )
117        return JK_PAGEUP;
118    if( strcasecmp( buffer, "PageDown" ) == 0 )
119        return JK_PAGEDOWN;
120
121    // Assume they are asking for a normal key, so convert the first
122    // character to an integer and return that
123    return (int)buffer[0];
124}
125
Note: See TracBrowser for help on using the repository browser.