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