Panda3D
keyboardButton.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file keyboardButton.cxx
10  * @author drose
11  * @date 2000-03-01
12  */
13 
14 #include "keyboardButton.h"
15 #include "buttonRegistry.h"
16 
17 #include <ctype.h>
18 
19 /**
20  * Returns the ButtonHandle associated with the particular ASCII character, if
21  * there is one, or ButtonHandle::none() if there is not.
22  */
24 ascii_key(char ascii_equivalent) {
25  return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent);
26 }
27 
28 #define DEFINE_KEYBD_BUTTON_HANDLE(KeyName) \
29  static ButtonHandle _##KeyName; \
30  ButtonHandle KeyboardButton::KeyName() { return _##KeyName; }
31 
32 DEFINE_KEYBD_BUTTON_HANDLE(space)
33 DEFINE_KEYBD_BUTTON_HANDLE(backspace)
34 DEFINE_KEYBD_BUTTON_HANDLE(tab)
35 DEFINE_KEYBD_BUTTON_HANDLE(enter)
36 DEFINE_KEYBD_BUTTON_HANDLE(escape)
37 DEFINE_KEYBD_BUTTON_HANDLE(f1)
38 DEFINE_KEYBD_BUTTON_HANDLE(f2)
39 DEFINE_KEYBD_BUTTON_HANDLE(f3)
40 DEFINE_KEYBD_BUTTON_HANDLE(f4)
41 DEFINE_KEYBD_BUTTON_HANDLE(f5)
42 DEFINE_KEYBD_BUTTON_HANDLE(f6)
43 DEFINE_KEYBD_BUTTON_HANDLE(f7)
44 DEFINE_KEYBD_BUTTON_HANDLE(f8)
45 DEFINE_KEYBD_BUTTON_HANDLE(f9)
46 DEFINE_KEYBD_BUTTON_HANDLE(f10)
47 DEFINE_KEYBD_BUTTON_HANDLE(f11)
48 DEFINE_KEYBD_BUTTON_HANDLE(f12)
49 DEFINE_KEYBD_BUTTON_HANDLE(f13)
50 DEFINE_KEYBD_BUTTON_HANDLE(f14)
51 DEFINE_KEYBD_BUTTON_HANDLE(f15)
52 DEFINE_KEYBD_BUTTON_HANDLE(f16)
53 DEFINE_KEYBD_BUTTON_HANDLE(left)
54 DEFINE_KEYBD_BUTTON_HANDLE(right)
55 DEFINE_KEYBD_BUTTON_HANDLE(up)
56 DEFINE_KEYBD_BUTTON_HANDLE(down)
57 DEFINE_KEYBD_BUTTON_HANDLE(page_up)
58 DEFINE_KEYBD_BUTTON_HANDLE(page_down)
59 DEFINE_KEYBD_BUTTON_HANDLE(home)
60 DEFINE_KEYBD_BUTTON_HANDLE(end)
61 DEFINE_KEYBD_BUTTON_HANDLE(insert)
62 DEFINE_KEYBD_BUTTON_HANDLE(del)
63 DEFINE_KEYBD_BUTTON_HANDLE(help)
64 DEFINE_KEYBD_BUTTON_HANDLE(meta)
65 DEFINE_KEYBD_BUTTON_HANDLE(caps_lock)
66 DEFINE_KEYBD_BUTTON_HANDLE(shift_lock)
67 DEFINE_KEYBD_BUTTON_HANDLE(scroll_lock)
68 DEFINE_KEYBD_BUTTON_HANDLE(num_lock)
69 DEFINE_KEYBD_BUTTON_HANDLE(print_screen)
70 DEFINE_KEYBD_BUTTON_HANDLE(pause)
71 DEFINE_KEYBD_BUTTON_HANDLE(menu)
72 DEFINE_KEYBD_BUTTON_HANDLE(shift)
73 DEFINE_KEYBD_BUTTON_HANDLE(control)
74 DEFINE_KEYBD_BUTTON_HANDLE(alt)
75 DEFINE_KEYBD_BUTTON_HANDLE(lshift)
76 DEFINE_KEYBD_BUTTON_HANDLE(rshift)
77 DEFINE_KEYBD_BUTTON_HANDLE(lcontrol)
78 DEFINE_KEYBD_BUTTON_HANDLE(rcontrol)
79 DEFINE_KEYBD_BUTTON_HANDLE(lalt)
80 DEFINE_KEYBD_BUTTON_HANDLE(ralt)
81 DEFINE_KEYBD_BUTTON_HANDLE(lmeta)
82 DEFINE_KEYBD_BUTTON_HANDLE(rmeta)
83 
84 
85 /**
86  * This is intended to be called only once, by the static initialization
87  * performed in config_putil.cxx.
88  */
91  ButtonRegistry::ptr()->register_button(_space, "space",
92  ButtonHandle::none(), ' ');
93  ButtonRegistry::ptr()->register_button(_backspace, "backspace",
94  ButtonHandle::none(), '\x08');
95  ButtonRegistry::ptr()->register_button(_tab, "tab",
96  ButtonHandle::none(), '\x09');
97  ButtonRegistry::ptr()->register_button(_enter, "enter",
98  ButtonHandle::none(), '\x0d');
99  ButtonRegistry::ptr()->register_button(_escape, "escape",
100  ButtonHandle::none(), '\x1b');
101  ButtonRegistry::ptr()->register_button(_del, "delete",
102  ButtonHandle::none(), '\x7f');
103 
104  ButtonRegistry::ptr()->register_button(_f1, "f1");
105  ButtonRegistry::ptr()->register_button(_f2, "f2");
106  ButtonRegistry::ptr()->register_button(_f3, "f3");
107  ButtonRegistry::ptr()->register_button(_f4, "f4");
108  ButtonRegistry::ptr()->register_button(_f5, "f5");
109  ButtonRegistry::ptr()->register_button(_f6, "f6");
110  ButtonRegistry::ptr()->register_button(_f7, "f7");
111  ButtonRegistry::ptr()->register_button(_f8, "f8");
112  ButtonRegistry::ptr()->register_button(_f9, "f9");
113  ButtonRegistry::ptr()->register_button(_f10, "f10");
114  ButtonRegistry::ptr()->register_button(_f11, "f11");
115  ButtonRegistry::ptr()->register_button(_f12, "f12");
116 
117  ButtonRegistry::ptr()->register_button(_f13, "f13");
118  ButtonRegistry::ptr()->register_button(_f14, "f14");
119  ButtonRegistry::ptr()->register_button(_f15, "f15");
120  ButtonRegistry::ptr()->register_button(_f16, "f16");
121 
122  ButtonRegistry::ptr()->register_button(_left, "arrow_left");
123  ButtonRegistry::ptr()->register_button(_right, "arrow_right");
124  ButtonRegistry::ptr()->register_button(_up, "arrow_up"); // cannot name this 'up' since it conflicts with key-release name 'up'
125  ButtonRegistry::ptr()->register_button(_down, "arrow_down");
126  ButtonRegistry::ptr()->register_button(_page_up, "page_up");
127  ButtonRegistry::ptr()->register_button(_page_down, "page_down");
128  ButtonRegistry::ptr()->register_button(_home, "home");
129  ButtonRegistry::ptr()->register_button(_end, "end");
130  ButtonRegistry::ptr()->register_button(_insert, "insert");
131  ButtonRegistry::ptr()->register_button(_help, "help");
132 
133  ButtonRegistry::ptr()->register_button(_shift, "shift");
134  ButtonRegistry::ptr()->register_button(_control, "control");
135  ButtonRegistry::ptr()->register_button(_alt, "alt");
136  ButtonRegistry::ptr()->register_button(_meta, "meta");
137  ButtonRegistry::ptr()->register_button(_caps_lock, "caps_lock");
138  ButtonRegistry::ptr()->register_button(_shift_lock, "shift_lock");
139  ButtonRegistry::ptr()->register_button(_num_lock, "num_lock");
140  ButtonRegistry::ptr()->register_button(_scroll_lock, "scroll_lock");
141  ButtonRegistry::ptr()->register_button(_print_screen, "print_screen");
142  ButtonRegistry::ptr()->register_button(_pause, "pause");
143  ButtonRegistry::ptr()->register_button(_menu, "menu");
144 
145  ButtonRegistry::ptr()->register_button(_lshift, "lshift", _shift);
146  ButtonRegistry::ptr()->register_button(_rshift, "rshift", _shift);
147  ButtonRegistry::ptr()->register_button(_lcontrol, "lcontrol", _control);
148  ButtonRegistry::ptr()->register_button(_rcontrol, "rcontrol", _control);
149  ButtonRegistry::ptr()->register_button(_lalt, "lalt", _alt);
150  ButtonRegistry::ptr()->register_button(_ralt, "ralt", _alt);
151  ButtonRegistry::ptr()->register_button(_lmeta, "lmeta", _meta);
152  ButtonRegistry::ptr()->register_button(_rmeta, "rmeta", _meta);
153 
154  // Also register all of the visible ASCII characters.
155  for (int i = 32; i < 127; i++) {
156  if (isgraph(i)) {
157  ButtonHandle key;
158  ButtonRegistry::ptr()->register_button(key, std::string(1, (char)i),
159  ButtonHandle::none(), i);
160  }
161  }
162 }
static void init_keyboard_buttons()
This is intended to be called only once, by the static initialization performed in config_putil....
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ButtonHandle find_ascii_button(char ascii_equivalent) const
Finds a ButtonHandle in the registry matching the indicated ASCII equivalent character.
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
bool register_button(ButtonHandle &button_handle, const std::string &name, ButtonHandle alias=ButtonHandle::none(), char ascii_equivalent='\0')
Registers a new ButtonHandle with the indicated name, and if specified, the indicated ASCII equivalen...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static ButtonHandle ascii_key(char ascii_equivalent)
Returns the ButtonHandle associated with the particular ASCII character, if there is one,...