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

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