vsg: include/vsg/ui/Keyboard.h Source File

vsg 1.1.8 VulkanSceneGraph library

Loading...
Searching...
No Matches
Keyboard.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2023 Robert Osfield
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12
13</editor-fold> */
14
15#include <vsg/ui/ApplicationEvent.h>
16#include <vsg/ui/KeyEvent.h>
17
18namespace vsg
19{
20
22 class VSG_DECLSPEC Keyboard : public Inherit<Visitor, Keyboard>
23 {
24 public:
25 void apply(KeyPressEvent& keyPress) override;
26 void apply(KeyReleaseEvent& keyRelease) override;
27 void apply(FocusInEvent& focusIn) override;
28 void apply(FocusOutEvent& focusOut) override;
29
30 struct KeyHistory
31 {
32 vsg::time_point timeOfFirstKeyPress = {};
33 vsg::time_point timeOfLastKeyPress = {};
34 vsg::time_point timeOfKeyRelease = {};
35 bool handled = false;
36 };
37
38 std::map<KeySymbol, KeyHistory> keyState;
39
41 bool pressed(KeySymbol key, bool ignore_handled_keys = true) const;
42
45 std::pair<double, double> times(KeySymbol key, bool ignore_handled_keys = true) const;
46 };
47 VSG_type_name(vsg::Keyboard);
48
49} // namespace vsg
vsg::FocusInEvent
FocusInEvent represents a window acquiring focus event.
Definition WindowEvent.h:98
vsg::FocusOutEvent
FocusOutEvent represents a window losing focus event.
Definition WindowEvent.h:109
vsg::Inherit
Definition Inherit.h:28
vsg::KeyPressEvent
KeyPressEvent represents a key press event.
Definition KeyEvent.h:309
vsg::KeyReleaseEvent
KeyReleaseEvent represents a key release event.
Definition KeyEvent.h:320
vsg::Keyboard
Keyboard tracks keyboard events to enable the querying of the key pressed state and how long the key ...
Definition Keyboard.h:23
vsg::Keyboard::times
std::pair< double, double > times(KeySymbol key, bool ignore_handled_keys=true) const
vsg::Keyboard::pressed
bool pressed(KeySymbol key, bool ignore_handled_keys=true) const
return true if key is currently pressed
vsg::Keyboard::KeyHistory
Definition Keyboard.h:31