VR-Engage  2.2
Loading...
Searching...
No Matches
vrvKeyboardMouseDevice.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies, Inc.
3** All rights reserved.
4*******************************************************************************/
5
6//! \file
7//! \brief Input device that processes keyboard and mouse events
8
9#pragma once
10
11#include "vreInput/export.h"
13#include "vreInput/inputData.h"
14
16
17#include <vrvCore/DtEventProcessorInterface.h>
18#include <vrvCore/DtMouseEvent.h>
19#include <memory>
20
21
22namespace makVrv
23{
24//! Forward declarations
25class DtChannel;
26} // namespace makVrv
27
28namespace makVre
29{
30//! Forward declarations
31class DtMouseControl;
32class DtInitTable;
33class DtPlayerStation;
34
35//! \brief Input device that processes keyboard and mouse events from VR-Vantage
36//!
37//! This class bridges the gap between the core event system and the input system
38//! by implementing both DtInputDevice and DtEventProcessorInterface. It receives
39//! keyboard and mouse events from the core system and translates them into
40//! DtInputData structures that can be processed by the input manager.
41class VREINPUT_DLL DtVrvKeyboardMouseDevice : public DtInputDevice, makVrv::DtEventProcessorInterface
42{
43public:
44 //! \brief Structure for keyboard input configuration
45 //!
46 //! Used to configure mappings between keyboard keys and input actions
47 struct KeyInput
48 {
49 std::string key; //!< Key identifier (key name or code)
50 std::string keyState; //!< State of the key (pressed, released, etc.)
51 std::string modifier; //!< Modifier keys that must be active (shift, ctrl, etc.)
52 double value; //!< Value to assign to the input when triggered
53 };
54
55 //! \brief Structure for keyboard action definition
56 //!
57 //! Defines an action that can be triggered by a keyboard input
59 {
60 std::string name; //!< Name of the action to trigger
61 double value; //!< Value to assign to the action when triggered
62 };
63
64 //! \brief Default constructor
65 //!
66 //! Initializes the event processor and sets up default values
68
69 //! \brief Virtual destructor
70 //!
71 //! Cleans up resources owned by the event processor
72 virtual ~DtVrvKeyboardMouseDevice() override;
73
74 //! \brief Initializes the event processor
75 //!
76 //! Sets up the event processor with the input manager and initializes
77 //! mouse control and event handling structures. Registers message handlers.
78 //!
79 //! \param mgr Reference to the input manager that owns this device
80 //! \return True if initialization succeeded, false otherwise
81 virtual bool init(DtVreInputManager& mgr) override;
82
83 //! \brief Shuts down the event processor
84 //!
85 //! Unregisters message handlers and cleans up resources allocated during initialization
86 virtual void shutdown() override;
87
88 //! \brief Reports the current state of input device controls
89 //!
90 //! Empty implementation as there's no persistent state to report for keyboard/mouse
91 virtual void reportCurrentState() override {};
92
93 //! \brief Updates the event processor for the current frame
94 //!
95 //! Handles time-based updates including mouse movement processing
96 //!
97 //! \param dt Delta time in seconds since the last frame
98 virtual void tick(double dt) override;
99
100 //! \brief Processes keyboard events from the core system
101 //!
102 //! Translates core keyboard events into input data structures and forwards
103 //! them to the input manager for processing.
104 //!
105 //! \param ev The keyboard event to process
106 //! \param channel The channel from which the event originated
107 //! \return True if the event was handled, false otherwise
108 virtual bool processKeyboardEvent(const makVrv::DtKeyEvent& ev, makVrv::DtChannel& channel) override;
109
110 //! \brief Processes mouse events from the core system
111 //!
112 //! Translates core mouse events (clicks, scrolls) into input data structures
113 //! and forwards them to the input manager for processing.
114 //!
115 //! \param ev The mouse event to process
116 //! \param channel The channel from which the event originated
117 //! \return True if the event was handled, false otherwise
118 virtual bool processMouseEvent(const makVrv::DtMouseEvent& ev, makVrv::DtChannel& channel) override;
119
120 //! \brief Processes mouse movement events
121 //!
122 //! Handles mouse movement and converts it into input data for the input manager.
123 //! This is called separately from processMouseEvent for continuous mouse movement.
124 //!
125 //! \param x The x-coordinate of the mouse cursor
126 //! \param y The y-coordinate of the mouse cursor
127 virtual void processMouseMove(float x, float y);
128
129 //! \brief Gets the class name of this event processor
130 //!
131 //! Implements the DtEventProcessorInterface requirement to provide a class name.
132 //!
133 //! \return Reference to a string containing the class name
134 virtual const std::string& className() override;
135
136protected:
137 //! \brief Handles messages to enable or disable VRV input processing
138 //!
139 //! Message handler that toggles whether VRV input events are processed
140 //!
141 //! \param msg Pointer to the message to handle
142 //! \return Result indicating whether the message was handled
144
145 //! \brief Sets up mouse click input data
146 //!
147 //! Helper method to populate mouse input data structure for button clicks
148 //!
149 //! \param button The mouse button that was clicked
150 //! \param doubleClick Whether this is a double-click event
151 //! \param raised Whether the button was raised (released) or pressed
152 virtual void setMouseClickData(DtMouseButton button, bool doubleClick, bool raised);
153
154 //! \brief Class name for identification in the event system
155 std::string myClassName;
156
157 //! \brief Pointer to the input manager that owns this device
159
160 //! \brief Flag indicating whether VRV input processing is enabled
162
163 //! \brief Reusable structure for mouse input data
165
166 //! \brief Reusable structure for keyboard input data
168
169 //! \brief Mouse control object for handling mouse behavior
170 std::unique_ptr<DtMouseControl> myMouseControl;
171
172 //! \brief Timestamp of the last mouse move update
174
175 //! \brief Tracking state for double-click detection (one entry per button)
176 std::vector<bool> myMouseDoubleClickState{false, false, false};
177};
178
179} // namespace makVre
Table-based access to Lua state for configuration data.
Definition initializer.h:38
DtInputDevice()
Default constructor.
Definition inputDevice.h:28
Manages mouse control state and behavior.
Definition mouseControl.h:72
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Central manager for input device handling, action mapping, and input processing.
Definition vreInputManager.h:81
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
virtual DtVreMessageResult handleSetVRVInputEnabled(DtVreMessage *msg)
Handles messages to enable or disable VRV input processing.
std::vector< bool > myMouseDoubleClickState
Tracking state for double-click detection (one entry per button)
Definition vrvKeyboardMouseDevice.h:176
virtual const std::string & className() override
Gets the class name of this event processor.
virtual void tick(double dt) override
Updates the event processor for the current frame.
DtInputData myMouseInputData
Reusable structure for mouse input data.
Definition vrvKeyboardMouseDevice.h:164
DtVrvKeyboardMouseDevice()
Default constructor.
virtual bool init(DtVreInputManager &mgr) override
Initializes the event processor.
double myLastMouseMoveUpdate
Timestamp of the last mouse move update.
Definition vrvKeyboardMouseDevice.h:173
virtual void processMouseMove(float x, float y)
Processes mouse movement events.
bool myVRVInputEnabled
Flag indicating whether VRV input processing is enabled.
Definition vrvKeyboardMouseDevice.h:161
virtual ~DtVrvKeyboardMouseDevice() override
Virtual destructor.
DtVreInputManager * myManager
Pointer to the input manager that owns this device.
Definition vrvKeyboardMouseDevice.h:158
std::unique_ptr< DtMouseControl > myMouseControl
Mouse control object for handling mouse behavior.
Definition vrvKeyboardMouseDevice.h:170
virtual void shutdown() override
Shuts down the event processor.
virtual void setMouseClickData(DtMouseButton button, bool doubleClick, bool raised)
Sets up mouse click input data.
virtual bool processMouseEvent(const makVrv::DtMouseEvent &ev, makVrv::DtChannel &channel) override
Processes mouse events from the core system.
virtual void reportCurrentState() override
Reports the current state of input device controls.
Definition vrvKeyboardMouseDevice.h:91
std::string myClassName
Class name for identification in the event system.
Definition vrvKeyboardMouseDevice.h:155
DtInputData myKeyboardInputData
Reusable structure for keyboard input data.
Definition vrvKeyboardMouseDevice.h:167
virtual bool processKeyboardEvent(const makVrv::DtKeyEvent &ev, makVrv::DtChannel &channel) override
Processes keyboard events from the core system.
Defines DLL export/import macros for the vreInput library.
#define VREINPUT_DLL
DLL export/import macro for the vreInput library.
Definition export.h:25
Defines data structures and enumerations for input device data.
Abstract base class for input device implementations.
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
enum DtMouseButton { DtLeftButton=0, DtRightButton, DtMiddleButton } DtMouseButton
Enumeration of mouse button types.
Definition inputData.h:45
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
Definition appLauncherComponent.h:28
Structure for transferring input data through the input system.
Definition inputData.h:89
Structure for keyboard input configuration.
Definition vrvKeyboardMouseDevice.h:48
std::string modifier
Modifier keys that must be active (shift, ctrl, etc.)
Definition vrvKeyboardMouseDevice.h:51
std::string key
Key identifier (key name or code)
Definition vrvKeyboardMouseDevice.h:49
std::string keyState
State of the key (pressed, released, etc.)
Definition vrvKeyboardMouseDevice.h:50
double value
Value to assign to the input when triggered.
Definition vrvKeyboardMouseDevice.h:52
Structure for keyboard action definition.
Definition vrvKeyboardMouseDevice.h:59
double value
Value to assign to the action when triggered.
Definition vrvKeyboardMouseDevice.h:61
std::string name
Name of the action to trigger.
Definition vrvKeyboardMouseDevice.h:60
Defines the base class for all VREngage messages.