Global Keyboard Shortcuts
In guiSET you can tell Frame to call your method when a certain keyboard combination is
pressed by the user. A shortcut consists of a number of so-called modifiers (Ctrl,
Shift,Alt) and a key, for example A.
To represent shortcuts in guiSET there is a Shortcut class (also see
Reference).
The constructor takes either a char as key and three booleans for Ctrl/Shift/Alt or a char as key and an
arbitrary number of modifiers.
Examples for first version:
new Shortcut('A', true, false, true)- Ctrl+Alt+Anew Shortcut('+', false, true, false)- Shift++new Shortcut('k', true, false, false)- Ctrl+Knew Shortcut('E', false, false, false)- E
Examples for second version:
new Shortcut('A', CONTROL, ALT)- Ctrl+Alt+Anew Shortcut('+', SHIFT)- Shift++-
new Shortcut('P', CONTROL, SHIFT, ALT)- Ctrl+Shift+Alt+P new Shortcut(' ')- Space
Now we can create a shortcut and register it to Frame.
Frame f;
void setup() {
f = new Frame(this);
f.registerShortcut(new Shortcut('M', CONTROL), "printStuff");
}
void draw() {}
void printStuff() {
println("User has pressed Ctrl+M");
}
Every time you press Ctrl+M now, printStuff() is called. There is one
exception though:
Strong Shortcuts
If you have a textbox in your sketch and the user has focused it (cursor blinks and you can enter input), then shortcuts will not be checked for by default. All input goes solely to the textbox. This makes sense if you have a shortcut for E that triggers for example saving a file. But in a bigger sketch you probably don't want to save the file every time the user hits 'e' while typing. Moreover, textboxes have their own Ctrl+C, Ctrl+A, Ctrl+V and Ctrl+X shortcuts which might conflict with shortcuts you want to implement.
If you need the shortcut to be triggered anyway, you can tell Frame it should be strong
by calling
f.registerShortcut(new Shortcut('M', CONTROL), "printStuff", this, true);.
The third parameter is just for specifying the object that implements you callback method "printStuff"
(mostly that is the sketch itself, so write this). The fourth parameter is a boolean for the
strong
property we just discussed. Default is false.
