]> git.mxchange.org Git - simgear.git/blob - simgear/canvas/events/KeyboardEvent.hxx
Add simple keyboard event demo application.
[simgear.git] / simgear / canvas / events / KeyboardEvent.hxx
1 ///@file
2 /// Keyboard event
3 //
4 // Copyright (C) 2014  Thomas Geymayer <tomgey@gmail.com>
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Library General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
19
20 #ifndef CANVAS_KEYBOARD_EVENT_HXX_
21 #define CANVAS_KEYBOARD_EVENT_HXX_
22
23 #include "DeviceEvent.hxx"
24
25 namespace simgear
26 {
27 namespace canvas
28 {
29
30   /**
31    * Keyboard (button up/down) event
32    */
33   class KeyboardEvent:
34     public DeviceEvent
35   {
36     public:
37
38       enum DOMKeyLocation
39       {
40         DOM_KEY_LOCATION_STANDARD = 0,
41         DOM_KEY_LOCATION_LEFT,
42         DOM_KEY_LOCATION_RIGHT,
43         DOM_KEY_LOCATION_NUMPAD
44       };
45
46       KeyboardEvent();
47       KeyboardEvent(const osgGA::GUIEventAdapter& ea);
48
49       void setKey(uint32_t key);
50       void setUnmodifiedKey(uint32_t key);
51       void setRepeat(bool repeat);
52
53       std::string key() const;
54       DOMKeyLocation location() const;
55       bool repeat() const { return _repeat; }
56
57       uint32_t charCode() const { return _key; }
58       uint32_t keyCode() const { return _unmodified_key; }
59
60       /// Whether the key which has triggered this event is a modifier
61       bool isModifier() const;
62
63     protected:
64       uint32_t _key,            //!< Key identifier for this event
65                _unmodified_key; //!< Virtual key identifier without any
66                                 //   modifiers applied
67       bool     _repeat;         //!< If key has been depressed long enough to
68                                 //   generate key repetition
69
70       mutable std::string _name; //!< Printable representation/name
71       mutable uint8_t _location; //!< Location of the key on the keyboard
72
73   };
74
75 } // namespace canvas
76 } // namespace simgear
77
78 #endif /* CANVAS_KEYBOARD_EVENT_HXX_ */