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

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

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