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()
{
}
...
}
Definition juce_ApplicationCommandManager.h:88
KeyPressMappingSet * getKeyMappings() const noexcept
Definition juce_ApplicationCommandManager.h:202
void registerAllCommandsForTarget(ApplicationCommandTarget *target)
Definition juce_ApplicationCommandManager.cpp:82
Definition juce_Component.h:36
void resetToDefaultMappings()
Definition juce_KeyPressMappingSet.cpp:104
bool restoreFromXml(const XmlElement &xmlVersion)
Definition juce_KeyPressMappingSet.cpp:213
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
@tags{GUI}
Called to indicate that a key has been pressed.
If your implementation returns true, then the key event is considered to have been consumed, and will not be passed on to any other components. If it returns false, then the key will be passed to other components that might want to use it.
- Parameters
-
| key | the keystroke, including modifier keys |
| originatingComponent | the component that received the key event |
- See also
- keyStateChanged, Component::keyPressed
Implements juce::KeyListener.
| bool juce::KeyPressMappingSet::keyStateChanged |
( |
bool | isKeyDown, |
|
|
Component * | originatingComponent ) |
|
overridevirtual |
Called when any key is pressed or released.
When this is called, classes that might be interested in the state of one or more keys can use KeyPress::isKeyCurrentlyDown() to check whether their key has changed.
If your implementation returns true, then the key event is considered to have been consumed, and will not be passed on to any other components. If it returns false, then the key will be passed to other components that might want to use it.
- Parameters
-
| originatingComponent | the component that received the key event |
| isKeyDown | true if a key is being pressed, false if one is being released |
- See also
- KeyPress, Component::keyStateChanged
Reimplemented from juce::KeyListener.
| bool juce::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