Deskflow 1.26.0.0
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 std::string m_screens;
49 };
50
51 using KeyButtonSet = std::set<KeyButton>;
52
54
55
57
61 virtual void updateKeyMap() = 0;
62
64
68 virtual void updateKeyState() = 0;
69
71
77
79
82 virtual void fakeKeyDown(KeyID id, KeyModifierMask mask, KeyButton button, const std::string &lang) = 0;
83
85
88 virtual bool
89 fakeKeyRepeat(KeyID id, KeyModifierMask mask, int32_t count, KeyButton button, const std::string &lang) = 0;
90
92
95 virtual bool fakeKeyUp(KeyButton button) = 0;
96
98
102 virtual void fakeAllKeysUp() = 0;
103
105
109 virtual void clearStaleModifiers()
110 {
111 // Default implementation does nothing
112 }
113
115
119 virtual bool fakeCtrlAltDel() = 0;
120
122
126 virtual bool fakeMediaKey(KeyID id) = 0;
127
129
131
133
137 virtual bool isKeyDown(KeyButton) const = 0;
138
140
145
147
152
154
157 virtual int32_t pollActiveGroup() const = 0;
158
160
164 virtual void pollPressedKeys(KeyButtonSet &pressedKeys) const = 0;
165
167};
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:114
KeyModifierMask m_mask
Definition IKeyState.h:45
static std::string join(const std::set< std::string > &destinations)
Definition IKeyState.cpp:93
static bool equal(const KeyInfo *, const KeyInfo *)
Definition IKeyState.cpp:85
std::string m_screens
Definition IKeyState.h:48
static bool contains(const char *screens, const std::string_view &name)
Definition IKeyState.cpp:66
KeyID m_key
Definition IKeyState.h:44
static bool isDefault(const char *screens)
Definition IKeyState.cpp:61
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:51
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:109
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.