#include <CKeyMap.h>
Collaboration diagram for CKeyMap:
accessors | |
const KeyItem * | mapKey (Keystrokes &keys, KeyID id, SInt32 group, ModifierToKeys &activeModifiers, KeyModifierMask ¤tState, KeyModifierMask desiredMask, bool isAutoRepeat) const |
Map key press/repeat to keystrokes. | |
SInt32 | getNumGroups () const |
Get number of groups. | |
SInt32 | getEffectiveGroup (SInt32 group, SInt32 offset) const |
Compute a group number. | |
const KeyItemList * | findCompatibleKey (KeyID id, SInt32 group, KeyModifierMask required, KeyModifierMask sensitive) const |
Find key entry compatible with modifiers. | |
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 CString | formatKey (KeyID key, KeyModifierMask) |
Get string for a key and modifier mask. | |
static bool | parseKey (const CString &, KeyID &) |
Parse a string into a key. | |
static bool | parseModifiers (CString &, KeyModifierMask &) |
Parse a string into a modifier mask. | |
Public Types | |
typedef std::vector< KeyItem > | KeyItemList |
The KeyButtons needed to synthesize a KeyID. | |
typedef std::vector< Keystroke > | Keystrokes |
A sequence of keystrokes. | |
typedef std::multimap< KeyModifierMask, KeyItem > | ModifierToKeys |
A mapping of a modifier to keys for that modifier. | |
typedef std::map< KeyButton, const KeyItem * > | ButtonToKeyMap |
A set of buttons. | |
typedef void(*) | ForeachKeyCallback (KeyID, SInt32 group, KeyItem &, void *userData) |
Callback type for foreachKey . | |
Public Member Functions | |
CKeyMap () | |
~CKeyMap () | |
manipulators | |
void | swap (CKeyMap &) |
Swap with another CKeyMap . | |
void | addKeyEntry (const KeyItem &item) |
Add a key entry. | |
void | addKeyAliasEntry (KeyID targetID, SInt32 group, KeyModifierMask targetRequired, KeyModifierMask targetSensitive, KeyID sourceID, KeyModifierMask sourceRequired, KeyModifierMask sourceSensitive) |
Add an alias key entry. | |
bool | addKeyCombinationEntry (KeyID id, SInt32 group, const KeyID *keys, UInt32 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. | |
void | addHalfDuplexModifier (KeyID key) |
Add a half-duplex modifier. | |
void | finish () |
Finish adding entries. | |
void | foreachKey (ForeachKeyCallback cb, void *userData) |
Iterate over all added keys items. | |
Classes | |
struct | KeyItem |
KeyID synthesis info. More... | |
class | Keystroke |
A keystroke. More... |
This class provides a keyboard mapping.
Definition at line 29 of file CKeyMap.h.
typedef std::vector<KeyItem> CKeyMap::KeyItemList |
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.
void CKeyMap::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.
Definition at line 202 of file CKeyMap.cpp.
void CKeyMap::addHalfDuplexModifier | ( | KeyID | key | ) |
Add a half-duplex modifier.
Records that modifier key key
is half-duplex. This is called to set user configurable half-duplex settings.
Definition at line 214 of file CKeyMap.cpp.
Referenced by CKeyState::setHalfDuplexMask().
void CKeyMap::addKeyAliasEntry | ( | KeyID | targetID, | |
SInt32 | 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
).
Definition at line 105 of file CKeyMap.cpp.
References addKeyEntry(), findCompatibleKey(), getEffectiveGroup(), and getNumGroups().
bool CKeyMap::addKeyCombinationEntry | ( | KeyID | id, | |
SInt32 | group, | |||
const KeyID * | keys, | |||
UInt32 | 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
.
Definition at line 135 of file CKeyMap.cpp.
References getNumGroups().
void CKeyMap::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.
Definition at line 63 of file CKeyMap.cpp.
References getNumGroups(), isDeadKey(), CKeyMap::KeyItem::m_button, CKeyMap::KeyItem::m_client, CKeyMap::KeyItem::m_dead, CKeyMap::KeyItem::m_generates, CKeyMap::KeyItem::m_group, CKeyMap::KeyItem::m_id, CKeyMap::KeyItem::m_required, and CKeyMap::KeyItem::m_sensitive.
Referenced by addKeyAliasEntry().
void CKeyMap::allowGroupSwitchDuringCompose | ( | ) |
Enable composition across groups.
If called then the keyboard map will allow switching between groups during key composition. Not all systems allow that.
Definition at line 196 of file CKeyMap.cpp.
void CKeyMap::clearHalfDuplexModifiers | ( | ) |
Remove all half-duplex modifiers.
Removes all half-duplex modifiers. This is called to set user configurable half-duplex settings.
Definition at line 208 of file CKeyMap.cpp.
Referenced by CKeyState::setHalfDuplexMask().
void CKeyMap::collectButtons | ( | const ModifierToKeys & | modifiers, | |
ButtonToKeyMap & | keys | |||
) | [static] |
Get buttons from modifier map.
Put all the keys in modifiers
into keys
.
Definition at line 387 of file CKeyMap.cpp.
const CKeyMap::KeyItemList * CKeyMap::findCompatibleKey | ( | KeyID | id, | |
SInt32 | 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 NULL 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
.
Definition at line 340 of file CKeyMap.cpp.
References getNumGroups().
Referenced by addKeyAliasEntry(), and CKeyState::getButton().
void CKeyMap::finish | ( | ) |
Finish adding entries.
Called after adding entries, this does some internal housekeeping.
Definition at line 220 of file CKeyMap.cpp.
Referenced by CKeyState::updateKeyMap().
void CKeyMap::foreachKey | ( | ForeachKeyCallback | cb, | |
void * | userData | |||
) |
Iterate over all added keys items.
Calls cb
for every key item.
Definition at line 235 of file CKeyMap.cpp.
Referenced by CKeyState::updateKeyState().
CString CKeyMap::formatKey | ( | KeyID | key, | |
KeyModifierMask | ||||
) | [static] |
Get string for a key and modifier mask.
Converts a key and modifier mask into a string representing the combination.
Definition at line 1142 of file CKeyMap.cpp.
References CStringUtil::print().
Referenced by CInputFilter::CMouseButtonAction::format(), CInputFilter::CKeystrokeAction::format(), CInputFilter::CMouseButtonCondition::format(), CInputFilter::CKeystrokeCondition::format(), CXWindowsScreen::registerHotKey(), COSXScreen::registerHotKey(), and CMSWindowsScreen::registerHotKey().
KeyModifierMask CKeyMap::getCommandModifiers | ( | ) | const |
Returns the modifiers that when combined with other keys indicate a command (e.g. shortcut or hotkey).
Definition at line 375 of file CKeyMap.cpp.
Referenced by isCommand().
KeyID CKeyMap::getDeadKey | ( | KeyID | key | ) | [static] |
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.
Definition at line 1084 of file CKeyMap.cpp.
References isDeadKey().
SInt32 CKeyMap::getEffectiveGroup | ( | SInt32 | group, | |
SInt32 | offset | |||
) | const |
Compute a group number.
Returns the number of the group offset
groups after group group
.
Definition at line 334 of file CKeyMap.cpp.
References getNumGroups().
Referenced by addKeyAliasEntry(), and CKeyState::getEffectiveGroup().
SInt32 CKeyMap::getNumGroups | ( | ) | const |
Get number of groups.
Returns the number of keyboard groups (independent layouts) in the map.
Definition at line 328 of file CKeyMap.cpp.
Referenced by addKeyAliasEntry(), addKeyCombinationEntry(), addKeyEntry(), findCompatibleKey(), and getEffectiveGroup().
void CKeyMap::initModifierKey | ( | KeyItem & | item | ) | [static] |
Set modifier key state.
Sets the modifier key state (m_generates
and m_lock
) in item
based on the m_id
in item
.
Definition at line 397 of file CKeyMap.cpp.
References CKeyMap::KeyItem::m_generates, CKeyMap::KeyItem::m_id, and CKeyMap::KeyItem::m_lock.
Referenced by CMSWindowsKeyState::getKeyMap().
bool CKeyMap::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.
Definition at line 369 of file CKeyMap.cpp.
References getCommandModifiers().
Referenced by mapKey().
bool CKeyMap::isDeadKey | ( | KeyID | key | ) | [static] |
Test for a dead key.
Returns true
if key
is a dead key.
Definition at line 1078 of file CKeyMap.cpp.
Referenced by addKeyEntry(), and getDeadKey().
bool CKeyMap::isHalfDuplex | ( | KeyID | key, | |
KeyButton | button | |||
) | const |
Test if modifier is half-duplex.
Returns true
iff modifier key key
or button button
is half-duplex.
Definition at line 363 of file CKeyMap.cpp.
Referenced by CKeyState::sendKeyEvent().
const CKeyMap::KeyItem * CKeyMap::mapKey | ( | Keystrokes & | keys, | |
KeyID | id, | |||
SInt32 | group, | |||
ModifierToKeys & | activeModifiers, | |||
KeyModifierMask & | currentState, | |||
KeyModifierMask | desiredMask, | |||
bool | isAutoRepeat | |||
) | const |
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 NULL if the key cannot be mapped.
Definition at line 254 of file CKeyMap.cpp.
References isCommand(), and CKeyMap::KeyItem::m_button.
Referenced by CKeyState::fakeKeyDown(), and CKeyState::fakeKeyRepeat().
bool CKeyMap::parseKey | ( | const CString & | , | |
KeyID & | ||||
) | [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.
Definition at line 1175 of file CKeyMap.cpp.
Referenced by CConfigReadContext::parseKeystroke().
bool CKeyMap::parseModifiers | ( | CString & | , | |
KeyModifierMask & | ||||
) | [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.
Definition at line 1210 of file CKeyMap.cpp.
Referenced by CConfigReadContext::parseKeystroke(), CConfigReadContext::parseModifier(), and CConfigReadContext::parseMouse().