Deskflow 1.22.0.197
Keyboard and mouse sharing utility
|
Key map. More...
#include <KeyMap.h>
Classes | |
struct | KeyItem |
KeyID synthesis info. More... | |
class | Keystroke |
A keystroke. More... |
Public Types | |
using | KeyItemList = std::vector<KeyItem> |
The KeyButtons needed to synthesize a KeyID. | |
using | Keystrokes = std::vector<Keystroke> |
A sequence of keystrokes. | |
using | ModifierToKeys = std::multimap<KeyModifierMask, KeyItem> |
A mapping of a modifier to keys for that modifier. | |
using | ButtonToKeyMap = std::map<KeyButton, const KeyItem *> |
A set of buttons. | |
using | ForeachKeyCallback = void (*)(KeyID, int32_t group, KeyItem &, void *userData) |
Callback type for foreachKey . |
Public Member Functions | |
KeyMap () | |
virtual | ~KeyMap ()=default |
manipulators | |
virtual void | swap (KeyMap &) noexcept |
Swap with another KeyMap . | |
void | addKeyEntry (const KeyItem &item) |
Add a key entry. | |
void | addKeyAliasEntry (KeyID targetID, int32_t group, KeyModifierMask targetRequired, KeyModifierMask targetSensitive, KeyID sourceID, KeyModifierMask sourceRequired, KeyModifierMask sourceSensitive) |
Add an alias key entry. | |
bool | addKeyCombinationEntry (KeyID id, int32_t group, const KeyID *keys, uint32_t numKeys) |
Add a key sequence entry. | |
void | allowGroupSwitchDuringCompose () |
Enable composition across groups. | |
void | addHalfDuplexButton (KeyButton button) |
Add a half-duplex button. | |
void | clearHalfDuplexModifiers () |
Remove all half-duplex modifiers. | |
virtual void | addHalfDuplexModifier (KeyID key) |
Add a half-duplex modifier. | |
virtual void | finish () |
Finish adding entries. | |
virtual void | foreachKey (ForeachKeyCallback cb, void *userData) |
Iterate over all added keys items. |
Friends | |
class | KeyMapTests |
accessors | |
virtual const KeyItem * | mapKey (Keystrokes &keys, KeyID id, int32_t group, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, KeyModifierMask desiredMask, bool isAutoRepeat, const std::string &lang) const |
Map key press/repeat to keystrokes. | |
void | setLanguageData (std::vector< std::string > layouts) |
int32_t | getNumGroups () const |
Get number of groups. | |
int32_t | getEffectiveGroup (int32_t group, int32_t offset) const |
Compute a group number. | |
const KeyItemList * | findCompatibleKey (KeyID id, int32_t group, KeyModifierMask required, KeyModifierMask sensitive) const |
Find key entry compatible with modifiers. | |
virtual bool | isHalfDuplex (KeyID key, KeyButton button) const |
Test if modifier is half-duplex. | |
bool | isCommand (KeyModifierMask mask) const |
Test if modifiers indicate a command. | |
KeyModifierMask | getCommandModifiers () const |
static void | collectButtons (const ModifierToKeys &modifiers, ButtonToKeyMap &keys) |
Get buttons from modifier map. | |
static void | initModifierKey (KeyItem &item) |
Set modifier key state. | |
static bool | isDeadKey (KeyID key) |
Test for a dead key. | |
static KeyID | getDeadKey (KeyID key) |
Get corresponding dead key. | |
static std::string | formatKey (KeyID key, KeyModifierMask) |
Get string for a key and modifier mask. | |
static bool | parseKey (const std::string &, KeyID &) |
Parse a string into a key. | |
static bool | parseModifiers (std::string &, KeyModifierMask &) |
Parse a string into a modifier mask. |
Key map.
This class provides a keyboard mapping.
using deskflow::KeyMap::ButtonToKeyMap = std::map<KeyButton, const KeyItem *> |
A set of buttons.
using deskflow::KeyMap::ForeachKeyCallback = void (*)(KeyID, int32_t group, KeyItem &, void *userData) |
Callback type for foreachKey
.
using deskflow::KeyMap::KeyItemList = std::vector<KeyItem> |
The KeyButtons needed to synthesize a KeyID.
An ordered list of KeyItems
produces a particular KeyID. If the KeyID can be synthesized directly then there is one entry in the list. If dead keys are required then they're listed first. A list is the minimal set of keystrokes necessary to synthesize the KeyID, so it doesn't include no-ops. A list does not include any modifier keys unless the KeyID is a modifier, in which case it has exactly one KeyItem for the modifier itself.
using deskflow::KeyMap::Keystrokes = std::vector<Keystroke> |
A sequence of keystrokes.
using deskflow::KeyMap::ModifierToKeys = std::multimap<KeyModifierMask, KeyItem> |
A mapping of a modifier to keys for that modifier.
deskflow::KeyMap::KeyMap | ( | ) |
|
virtualdefault |
void deskflow::KeyMap::addHalfDuplexButton | ( | KeyButton | button | ) |
Add a half-duplex button.
Records that button button
is a half-duplex key. This is called when translating the system's keyboard map. It's independent of the half-duplex modifier calls.
|
virtual |
Add a half-duplex modifier.
Records that modifier key key
is half-duplex. This is called to set user configurable half-duplex settings.
void deskflow::KeyMap::addKeyAliasEntry | ( | KeyID | targetID, |
int32_t | group, | ||
KeyModifierMask | targetRequired, | ||
KeyModifierMask | targetSensitive, | ||
KeyID | sourceID, | ||
KeyModifierMask | sourceRequired, | ||
KeyModifierMask | sourceSensitive ) |
Add an alias key entry.
If targetID
with the modifiers given by targetRequired
and targetSensitive
is not available in group group
then find an entry for sourceID
with modifiers given by sourceRequired
and sourceSensitive
in any group with exactly one item and, if found, add a new item just like it except using id targetID
. This effectively makes the sourceID
an alias for targetID
(i.e. we can generate targetID
using sourceID
).
bool deskflow::KeyMap::addKeyCombinationEntry | ( | KeyID | id, |
int32_t | group, | ||
const KeyID * | keys, | ||
uint32_t | numKeys ) |
Add a key sequence entry.
Adds the sequence of keys keys
(numKeys
elements long) to synthesize key id
in group group
. This looks up in the map each key in keys
. If all are found then each key is converted to the button for that key and the buttons are added as the entry for id
. If id
is already in the map or at least one key in keys
is not in the map then nothing is added and this returns false
, otherwise it returns true
.
void deskflow::KeyMap::addKeyEntry | ( | const KeyItem & | item | ) |
Add a key entry.
Adds item
to the entries for the item's id and group. The m_dead
member is set automatically.
void deskflow::KeyMap::allowGroupSwitchDuringCompose | ( | ) |
Enable composition across groups.
If called then the keyboard map will allow switching between groups during key composition. Not all systems allow that.
void deskflow::KeyMap::clearHalfDuplexModifiers | ( | ) |
Remove all half-duplex modifiers.
Removes all half-duplex modifiers. This is called to set user configurable half-duplex settings.
|
static |
Get buttons from modifier map.
Put all the keys in modifiers
into keys
.
const KeyMap::KeyItemList * deskflow::KeyMap::findCompatibleKey | ( | KeyID | id, |
int32_t | group, | ||
KeyModifierMask | required, | ||
KeyModifierMask | sensitive ) const |
Find key entry compatible with modifiers.
Returns the KeyItemList
for the first entry for id
in group group
that is compatible with the given modifiers, or nullptr if there isn't one. A button list is compatible with a modifiers if it is either insensitive to all modifiers in sensitive
or it requires the modifiers to be in the state indicated by required
for every modifier indicated by sensitive
.
|
virtual |
Finish adding entries.
Called after adding entries, this does some internal housekeeping.
|
virtual |
Iterate over all added keys items.
Calls cb
for every key item.
|
static |
Get string for a key and modifier mask.
Converts a key and modifier mask into a string representing the combination.
KeyModifierMask deskflow::KeyMap::getCommandModifiers | ( | ) | const |
Returns the modifiers that when combined with other keys indicate a command (e.g. shortcut or hotkey).
Get corresponding dead key.
Returns the dead key corresponding to key
if one exists, otherwise return kKeyNone
. This returns key
if it's already a dead key.
int32_t deskflow::KeyMap::getEffectiveGroup | ( | int32_t | group, |
int32_t | offset ) const |
Compute a group number.
Returns the number of the group offset
groups after group group
.
int32_t deskflow::KeyMap::getNumGroups | ( | ) | const |
Get number of groups.
Returns the number of keyboard groups (independent layouts) in the map.
|
static |
Set modifier key state.
Sets the modifier key state (m_generates
and m_lock
) in item
based on the m_id
in item
.
bool deskflow::KeyMap::isCommand | ( | KeyModifierMask | mask | ) | const |
Test if modifiers indicate a command.
Returns true
iff the modifiers in mask
contain any command modifiers. A command modifier is used for keyboard shortcuts and hotkeys, Rather than trying to synthesize a character, a command is trying to synthesize a particular set of buttons. So it's not important to match the shift or AltGr state to achieve a character but it is important to match the modifier state exactly.
|
static |
Test for a dead key.
Returns true
if key
is a dead key.
Test if modifier is half-duplex.
Returns true
iff modifier key key
or button button
is half-duplex.
|
virtual |
Map key press/repeat to keystrokes.
Converts press/repeat of key id
in group group
with current modifiers as given in currentState
and the desired modifiers in desiredMask
into the keystrokes necessary to synthesize that key event in keys
. It returns the KeyItem
of the key being pressed/repeated, or nullptr if the key cannot be mapped.
|
static |
Parse a string into a key.
Converts a string into a key. Returns true
on success and false
if the string cannot be parsed.
|
static |
Parse a string into a modifier mask.
Converts a string into a modifier mask. Returns true
on success and false
if the string cannot be parsed. The modifiers plus any remaining leading and trailing whitespace is stripped from the input string.
void deskflow::KeyMap::setLanguageData | ( | std::vector< std::string > | layouts | ) |
|
friend |