Coin: SoKeyboardEvent.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/kogt/

SoKeyboardEvent.h
1#ifndef COIN_SOKEYBOARDEVENT_H
2#define COIN_SOKEYBOARDEVENT_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/events/SoButtonEvent.h>
37
38// Avoid problem with Microsoft Visual C++ Win32 API headers (yes,
39// they actually #define DELETE in their WINNT.H header file).
40#ifdef DELETE
41#define SOKEYBOARDEVENT_UNDEF_DELETE
42#undef DELETE
43#endif // DELETE
44
45
46#define SO_KEY_PRESS_EVENT(EVENT, KEY) \
47 (SoKeyboardEvent::isKeyPressEvent(EVENT, SoKeyboardEvent::KEY))
48
49#define SO_KEY_RELEASE_EVENT(EVENT, KEY) \
50 (SoKeyboardEvent::isKeyReleaseEvent(EVENT, SoKeyboardEvent::KEY))
51
52
53 class COIN_DLL_API SoKeyboardEvent : public SoButtonEvent {
54 typedef SoButtonEvent inherited;
55 SO_EVENT_HEADER();
56
57public:
58 static void initClass(void);
59
60 SoKeyboardEvent(void);
61 virtual ~SoKeyboardEvent();
62
63 enum Key {
64 ANY = 0,
65 UNDEFINED = 1,
66
67 LEFT_SHIFT = 0xffe1, RIGHT_SHIFT, LEFT_CONTROL, RIGHT_CONTROL,
68 LEFT_ALT = 0xffe9, RIGHT_ALT,
69
70 NUMBER_0 = 0x0030, NUMBER_1, NUMBER_2, NUMBER_3, NUMBER_4, NUMBER_5,
71 NUMBER_6, NUMBER_7, NUMBER_8, NUMBER_9,
72
73 A = 0x0061, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T,
74 U, V, W, X, Y, Z,
75
76 HOME = 0xff50, LEFT_ARROW, UP_ARROW, RIGHT_ARROW, DOWN_ARROW,
77 PAGE_UP, PAGE_DOWN, END,
78 PRIOR = 0xff55, NEXT,
79
80 PAD_ENTER = 0xff8d,
81 PAD_F1 = 0xff91, PAD_F2, PAD_F3, PAD_F4,
82 PAD_0 = 0xff9e, PAD_1 = 0xff9c, PAD_2 = 0xff99, PAD_3 = 0xff9b,
83 PAD_4 = 0xff96, PAD_5 = 0xff9d, PAD_6 = 0xff98, PAD_7 = 0xff95,
84 PAD_8 = 0xff97, PAD_9 = 0xff9a,
85 PAD_ADD = 0xffab, PAD_SUBTRACT = 0xffad,
86 PAD_MULTIPLY = 0xffaa, PAD_DIVIDE = 0xffaf,
87 PAD_SPACE = 0xff8d, PAD_TAB = 0xff89,
88 PAD_INSERT = 0xff9e, PAD_DELETE = 0xff9f, PAD_PERIOD = 0xff9f,
89
90 F1 = 0xffbe, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
91
92 BACKSPACE = 0xff08, TAB = 0xff09,
93 RETURN = 0xff0d, ENTER = 0xff0d,
94 PAUSE = 0xff13, SCROLL_LOCK = 0xff14,
95 ESCAPE = 0xff1b, DELETE = 0xffff, KEY_DELETE = DELETE,
96 PRINT = 0xff61, INSERT = 0xff63,
97 NUM_LOCK = 0xff7f, CAPS_LOCK = 0xffe5, SHIFT_LOCK = 0xffe6,
98
99 SPACE = 0x0020, APOSTROPHE = 0x0027,
100 COMMA = 0x002c, MINUS = 0x002d, PERIOD = 0x002e, SLASH = 0x002f,
101 SEMICOLON = 0x003b, EQUAL = 0x003d,
102 BRACKETLEFT = 0x005b, BACKSLASH = 0x005c,
103 BRACKETRIGHT = 0x005d, GRAVE = 0x0060
104 };
105
106 void setKey(Key key);
107 Key getKey(void) const;
108
109 void setPrintableCharacter(const char c);
110 char getPrintableCharacter(void) const;
111
112 static SbBool isKeyPressEvent(const SoEvent * e, Key whichKey);
113 static SbBool isKeyReleaseEvent(const SoEvent * e, Key whichKey);
114
115 static SbBool enumToString(Key enumval, SbString & stringrep);
116
117private:
118 Key key;
119 char printable;
120 char isprintableset;
121
122}; // SoKeyboardEvent
123
124// Avoid problem with Microsoft Win32 API headers (see above). Define
125// DELETE back to its value in the MSVC header file.
126//
127// FIXME: we shouldn't uncritically trust this value to come from the
128// MSVC headers, but rather check in the block at the top to see that
129// it matches the value we believe it does. Alternatively, we could
130// just don't bother to set it back -- it seems quite unlikely that
131// this would break any client code, but if so, it would be a simple
132// fix on the client side to get around it -- just rearrange
133// headers. 20040629 mortene.
134#ifdef SOKEYBOARDEVENT_UNDEF_DELETE
135#define DELETE (0x00010000L)
136#undef SOKEYBOARDEVENT_UNDEF_DELETE
137#endif // SOKEYBOARDEVENT_UNDEF_DELETE
138
139#endif // !COIN_SOKEYBOARDEVENT_H
SbString
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
SoButtonEvent::enumToString
static SbBool enumToString(State enumval, SbString &stringrep)
Definition SoButtonEvent.cpp:130
SoButtonEvent::initClass
static void initClass(void)
Definition SoButtonEvent.cpp:75
SoButtonEvent::SoButtonEvent
SoButtonEvent(void)
Definition SoButtonEvent.cpp:83
SoEvent
The SoEvent class is the base class for all Coin events.
Definition SoEvent.h:45
SoKeyboardEvent::SoKeyboardEvent
SoKeyboardEvent(void)
Definition SoKeyboardEvent.cpp:241
SoKeyboardEvent::Key
Key
Definition SoKeyboardEvent.h:63