Manages and edits a list of keypresses, which it uses to invoke the appropriate command in an ApplicationCommandManager.
More...
#include <juce_KeyPressMappingSet.h>
Manages and edits a list of keypresses, which it uses to invoke the appropriate command in an ApplicationCommandManager.
Normally, you won't actually create a KeyPressMappingSet directly, because each ApplicationCommandManager contains its own KeyPressMappingSet, so typically you'd create yourself an ApplicationCommandManager, and call its ApplicationCommandManager::getKeyMappings() method to get a pointer to its KeyPressMappingSet.
For one of these to actually use keypresses, you'll need to add it as a KeyListener to the top-level component for which you want to handle keystrokes. So for example:
{
public:
MyMainWindow()
{
}
...
}
KeyPressMappingSet derives from ChangeBroadcaster so that interested parties can register to be told when a command or mapping is added, removed, etc.
There's also a UI component called KeyMappingEditorComponent that can be used to easily edit the key mappings.
- See also
- Component::addKeyListener(), KeyMappingEditorComponent, ApplicationCommandManager
◆ KeyPressMappingSet() [1/2]
◆ KeyPressMappingSet() [2/2]
◆ ~KeyPressMappingSet()
KeyPressMappingSet::~KeyPressMappingSet |
( |
| ) |
|
◆ addChangeListener()
void ChangeBroadcaster::addChangeListener |
( |
ChangeListener * |
listener | ) |
|
|
inherited |
Registers a listener to receive change callbacks from this broadcaster.
Trying to add a listener that's already on the list will have no effect.
◆ addKeyPress()
void KeyPressMappingSet::addKeyPress |
( |
CommandID |
commandID, |
|
|
const KeyPress & |
newKeyPress, |
|
|
int |
insertIndex = -1 |
|
) |
| |
Assigns a keypress to a command.
If the keypress is already assigned to a different command, it will first be removed from that command, to avoid it triggering multiple functions.
- Parameters
-
commandID | the ID of the command that you want to add a keypress to. If this is 0, the keypress will be removed from anything that it was previously assigned to, but not re-assigned |
newKeyPress | the new key-press |
insertIndex | if this is less than zero, the key will be appended to the end of the list of keypresses; otherwise the new keypress will be inserted into the existing list at this index |
◆ clearAllKeyPresses() [1/2]
void KeyPressMappingSet::clearAllKeyPresses |
( |
| ) |
|
Removes all keypresses that are assigned to any commands.
◆ clearAllKeyPresses() [2/2]
void KeyPressMappingSet::clearAllKeyPresses |
( |
CommandID |
commandID | ) |
|
Removes all keypresses that are assigned to a particular command.
◆ containsMapping()
bool KeyPressMappingSet::containsMapping |
( |
CommandID |
commandID, |
|
|
const KeyPress & |
keyPress |
|
) |
| const |
|
noexcept |
Returns true if the given command is linked to this key.
◆ createXml()
XmlElement* KeyPressMappingSet::createXml |
( |
bool |
saveDifferencesFromDefaultSet | ) |
const |
Creates an XML representation of the current mappings.
This will produce a lump of XML that can be later reloaded using restoreFromXml() to recreate the current mapping state.
The object that is returned must be deleted by the caller.
- Parameters
-
saveDifferencesFromDefaultSet | if this is false, then all keypresses will be saved into the XML. If it's true, then the XML will only store the differences between the current mappings and the default mappings you'd get from calling resetToDefaultMappings(). The advantage of saving a set of differences from the default is that if you change the default mappings (in a new version of your app, for example), then these will be merged into a user's saved preferences. |
- See also
- restoreFromXml
◆ dispatchPendingMessages()
void ChangeBroadcaster::dispatchPendingMessages |
( |
| ) |
|
|
inherited |
If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately.
For thread-safety reasons, you must only call this method on the main message thread.
◆ findCommandForKeyPress()
CommandID KeyPressMappingSet::findCommandForKeyPress |
( |
const KeyPress & |
keyPress | ) |
const |
|
noexcept |
Looks for a command that corresponds to a keypress.
- Returns
- the UID of the command or 0 if none was found
◆ getCommandManager()
◆ getKeyPressesAssignedToCommand()
Returns a list of keypresses that are assigned to a particular command.
- Parameters
-
commandID | the command's ID |
◆ globalFocusChanged()
void KeyPressMappingSet::globalFocusChanged |
( |
Component * |
| ) |
|
|
overridevirtual |
◆ invokeCommand()
void KeyPressMappingSet::invokeCommand |
( |
const CommandID |
, |
|
|
const KeyPress & |
, |
|
|
const bool |
isKeyDown, |
|
|
const int |
millisecsSinceKeyPressed, |
|
|
Component * |
originator |
|
) |
| const |
|
private |
◆ keyPressed()
◆ keyStateChanged()
bool KeyPressMappingSet::keyStateChanged |
( |
bool |
isKeyDown, |
|
|
Component * |
|
|
) |
| |
|
overridevirtual |
◆ operator=()
◆ removeAllChangeListeners()
void ChangeBroadcaster::removeAllChangeListeners |
( |
| ) |
|
|
inherited |
Removes all listeners from the list.
◆ removeChangeListener()
void ChangeBroadcaster::removeChangeListener |
( |
ChangeListener * |
listener | ) |
|
|
inherited |
Unregisters a listener from the list.
If the listener isn't on the list, this won't have any effect.
◆ removeKeyPress() [1/2]
void KeyPressMappingSet::removeKeyPress |
( |
CommandID |
commandID, |
|
|
int |
keyPressIndex |
|
) |
| |
Removes one of the keypresses that are assigned to a command.
See the getKeyPressesAssignedToCommand() for the list of keypresses to which the keyPressIndex refers.
◆ removeKeyPress() [2/2]
void KeyPressMappingSet::removeKeyPress |
( |
const KeyPress & |
keypress | ) |
|
Removes a keypress from any command that it may be assigned to.
◆ resetToDefaultMapping()
void KeyPressMappingSet::resetToDefaultMapping |
( |
CommandID |
commandID | ) |
|
◆ resetToDefaultMappings()
void KeyPressMappingSet::resetToDefaultMappings |
( |
| ) |
|
◆ restoreFromXml()
bool KeyPressMappingSet::restoreFromXml |
( |
const XmlElement & |
xmlVersion | ) |
|
Tries to recreate the mappings from a previously stored state.
The XML passed in must have been created by the createXml() method.
If the stored state makes any reference to commands that aren't currently available, these will be ignored.
If the set of mappings being loaded was a set of differences (using createXml (true)), then this will call resetToDefaultMappings() and then merge the saved mappings on top. If the saved set was created with createXml (false), then this method will first clear all existing mappings and load the saved ones as a complete set.
- Returns
- true if it manages to load the XML correctly
- See also
- createXml
◆ sendChangeMessage()
void ChangeBroadcaster::sendChangeMessage |
( |
| ) |
|
|
inherited |
◆ sendSynchronousChangeMessage()
void ChangeBroadcaster::sendSynchronousChangeMessage |
( |
| ) |
|
|
inherited |
◆ commandManager
◆ keysDown
◆ mappings
The documentation for this class was generated from the following file: