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

Last change on this file since 682 was 555, checked in by Sam Hocevar, 10 years ago

ps3: make everything compile on the PS3. Of course, nothing links yet
because so much support is missing.

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