Panda3D

Loading...
Searching...
No Matches
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 */
23 ButtonHandle KeyboardButton::
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
32DEFINE_KEYBD_BUTTON_HANDLE(space)
33DEFINE_KEYBD_BUTTON_HANDLE(backspace)
34DEFINE_KEYBD_BUTTON_HANDLE(tab)
35DEFINE_KEYBD_BUTTON_HANDLE(enter)
36DEFINE_KEYBD_BUTTON_HANDLE(escape)
37DEFINE_KEYBD_BUTTON_HANDLE(f1)
38DEFINE_KEYBD_BUTTON_HANDLE(f2)
39DEFINE_KEYBD_BUTTON_HANDLE(f3)
40DEFINE_KEYBD_BUTTON_HANDLE(f4)
41DEFINE_KEYBD_BUTTON_HANDLE(f5)
42DEFINE_KEYBD_BUTTON_HANDLE(f6)
43DEFINE_KEYBD_BUTTON_HANDLE(f7)
44DEFINE_KEYBD_BUTTON_HANDLE(f8)
45DEFINE_KEYBD_BUTTON_HANDLE(f9)
46DEFINE_KEYBD_BUTTON_HANDLE(f10)
47DEFINE_KEYBD_BUTTON_HANDLE(f11)
48DEFINE_KEYBD_BUTTON_HANDLE(f12)
49DEFINE_KEYBD_BUTTON_HANDLE(f13)
50DEFINE_KEYBD_BUTTON_HANDLE(f14)
51DEFINE_KEYBD_BUTTON_HANDLE(f15)
52DEFINE_KEYBD_BUTTON_HANDLE(f16)
53DEFINE_KEYBD_BUTTON_HANDLE(left)
54DEFINE_KEYBD_BUTTON_HANDLE(right)
55DEFINE_KEYBD_BUTTON_HANDLE(up)
56DEFINE_KEYBD_BUTTON_HANDLE(down)
57DEFINE_KEYBD_BUTTON_HANDLE(page_up)
58DEFINE_KEYBD_BUTTON_HANDLE(page_down)
59DEFINE_KEYBD_BUTTON_HANDLE(home)
60DEFINE_KEYBD_BUTTON_HANDLE(end)
61DEFINE_KEYBD_BUTTON_HANDLE(insert)
62DEFINE_KEYBD_BUTTON_HANDLE(del)
63DEFINE_KEYBD_BUTTON_HANDLE(help)
64DEFINE_KEYBD_BUTTON_HANDLE(meta)
65DEFINE_KEYBD_BUTTON_HANDLE(caps_lock)
66DEFINE_KEYBD_BUTTON_HANDLE(shift_lock)
67DEFINE_KEYBD_BUTTON_HANDLE(scroll_lock)
68DEFINE_KEYBD_BUTTON_HANDLE(num_lock)
69DEFINE_KEYBD_BUTTON_HANDLE(print_screen)
70DEFINE_KEYBD_BUTTON_HANDLE(pause)
71DEFINE_KEYBD_BUTTON_HANDLE(menu)
72DEFINE_KEYBD_BUTTON_HANDLE(shift)
73DEFINE_KEYBD_BUTTON_HANDLE(control)
74DEFINE_KEYBD_BUTTON_HANDLE(alt)
75DEFINE_KEYBD_BUTTON_HANDLE(lshift)
76DEFINE_KEYBD_BUTTON_HANDLE(rshift)
77DEFINE_KEYBD_BUTTON_HANDLE(lcontrol)
78DEFINE_KEYBD_BUTTON_HANDLE(rcontrol)
79DEFINE_KEYBD_BUTTON_HANDLE(lalt)
80DEFINE_KEYBD_BUTTON_HANDLE(ralt)
81DEFINE_KEYBD_BUTTON_HANDLE(lmeta)
82DEFINE_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 */
89void KeyboardButton::
90 init_keyboard_buttons() {
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}
buttonRegistry.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
ButtonHandle
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition buttonHandle.h:26
ButtonRegistry::find_ascii_button
ButtonHandle find_ascii_button(char ascii_equivalent) const
Finds a ButtonHandle in the registry matching the indicated ASCII equivalent character.
Definition buttonRegistry.cxx:147
ButtonRegistry::register_button
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...
Definition buttonRegistry.cxx:44
ButtonRegistry::ptr
static ButtonRegistry * ptr()
Returns the pointer to the global ButtonRegistry object.
Definition buttonRegistry.I:29
KeyboardButton
This class is just used as a convenient namespace for grouping all of these handy functions that retu...
Definition keyboardButton.h:25
KeyboardButton::ascii_key
static ButtonHandle ascii_key(char ascii_equivalent)
Returns the ButtonHandle associated with the particular ASCII character, if there is one,...
Definition keyboardButton.cxx:24
KeyboardButton::init_keyboard_buttons
static void init_keyboard_buttons()
This is intended to be called only once, by the static initialization performed in config_putil....
Definition keyboardButton.cxx:90
keyboardButton.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.