Deskflow 1.24.0.365
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
IKeyState.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
4 * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
5 * SPDX-FileCopyrightText: (C) 2003 Chris Schoeneman
6 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
7 */
8
9#pragma once
10
11#include "base/IEventQueue.h"
12#include "deskflow/KeyTypes.h"
13
14#include <set>
15#include <string>
16
18
23{
24public:
25 explicit IKeyState(const IEventQueue *events);
26 virtual ~IKeyState() = default;
27 inline static const auto s_numButtons = 0x200;
28
30 class KeyInfo
31 {
32 public:
33 static KeyInfo *alloc(KeyID, KeyModifierMask, KeyButton, int32_t count);
34 static KeyInfo *alloc(KeyID, KeyModifierMask, KeyButton, int32_t count, const std::set<std::string> &destinations);
35 static KeyInfo *alloc(const KeyInfo &);
36
37 static bool isDefault(const char *screens);
38 static bool contains(const char *screens, const std::string_view &name);
39 static bool equal(const KeyInfo *, const KeyInfo *);
40 static std::string join(const std::set<std::string> &destinations);
41 static void split(const char *screens, std::set<std::string> &);
42
43 public:
47 int32_t m_count;
48 char *m_screens;
50 };
51
52 using KeyButtonSet = std::set<KeyButton>;
53
55
56
58
62 virtual void updateKeyMap() = 0;
63
65
69 virtual void updateKeyState() = 0;
70
72
78
80
83 virtual void fakeKeyDown(KeyID id, KeyModifierMask mask, KeyButton button, const std::string &lang) = 0;
84
86
89 virtual bool
90 fakeKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyButton button, const std::string &lang) = 0;
91
93
96 virtual bool fakeKeyUp(KeyButton button) = 0;
97
99
103 virtual void fakeAllKeysUp() = 0;
104
106
110 virtual void clearStaleModifiers()
111 {
112 // Default implementation does nothing
113 }
114
116
120 virtual bool fakeCtrlAltDel() = 0;
121
123
127 virtual bool fakeMediaKey(KeyID id) = 0;
128
130
132
134
138 virtual bool isKeyDown(KeyButton) const = 0;
139
141
146
148
153
155
158 virtual int32_t pollActiveGroup() const = 0;
159
161
165 virtual void pollPressedKeys(KeyButtonSet &pressedKeys) const = 0;
166
168};
static const struct sockaddr FAR * name
Definition ArchNetworkWinsock.cpp:28
uint32_t KeyID
Key ID.
Definition KeyTypes.h:21
uint16_t KeyButton
Key Code.
Definition KeyTypes.h:34
uint32_t KeyModifierMask
Modifier key mask.
Definition KeyTypes.h:44
Event queue interface.
Definition IEventQueue.h:29
Key event data.
Definition IKeyState.h:31
static void split(const char *screens, std::set< std::string > &)
Definition IKeyState.cpp:135
KeyModifierMask m_mask
Definition IKeyState.h:45
static std::string join(const std::set< std::string > &destinations)
Definition IKeyState.cpp:114
static bool equal(const KeyInfo *, const KeyInfo *)
Definition IKeyState.cpp:106
char * m_screens
Definition IKeyState.h:48
char m_screensBuffer[1]
Definition IKeyState.h:49
static bool contains(const char *screens, const std::string_view &name)
Definition IKeyState.cpp:87
KeyID m_key
Definition IKeyState.h:44
static bool isDefault(const char *screens)
Definition IKeyState.cpp:82
int32_t m_count
Definition IKeyState.h:47
static KeyInfo * alloc(KeyID, KeyModifierMask, KeyButton, int32_t count)
Definition IKeyState.cpp:26
KeyButton m_button
Definition IKeyState.h:46
std::set< KeyButton > KeyButtonSet
Definition IKeyState.h:52
virtual bool fakeKeyUp(KeyButton button)=0
Fake a key release.
virtual bool fakeKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyButton button, const std::string &lang)=0
Fake a key repeat.
virtual void setHalfDuplexMask(KeyModifierMask)=0
Set half-duplex mask.
virtual void clearStaleModifiers()
Clear stale modifiers.
Definition IKeyState.h:110
IKeyState(const IEventQueue *events)
Definition IKeyState.cpp:17
static const auto s_numButtons
Definition IKeyState.h:27
virtual void updateKeyMap()=0
Update the keyboard map.
virtual void fakeAllKeysUp()=0
Fake key releases for all fake pressed keys.
virtual KeyModifierMask pollActiveModifiers() const =0
Get the active modifiers from OS.
virtual void updateKeyState()=0
Update the key state.
virtual void fakeKeyDown(KeyID id, KeyModifierMask mask, KeyButton button, const std::string &lang)=0
Fake a key press.
virtual int32_t pollActiveGroup() const =0
Get the active keyboard layout from OS.
virtual bool isKeyDown(KeyButton) const =0
Test if key is pressed.
virtual bool fakeCtrlAltDel()=0
Fake ctrl+alt+del.
virtual ~IKeyState()=default
virtual void pollPressedKeys(KeyButtonSet &pressedKeys) const =0
Get the keys currently pressed from OS.
virtual bool fakeMediaKey(KeyID id)=0
Fake a media key.
virtual KeyModifierMask getActiveModifiers() const =0
Get the active modifiers.