“Map Combo Key to Phoneme [Java/Pjs]” by GoToLoop
https://openprocessing.org/sketch/1593616
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
Hold down some keys then release them
CC Attribution NonCommercial ShareAlike
Map Combo Key to Phoneme [Java/Pjs]
xxxxxxxxxx
/**
* Map Combo Key to Phoneme (v1.1.1) [Java/Pjs]
* GoToLoop (2022/Jun/07)
*
* https://Discourse.Processing.org/t/
* need-help-w-keyboard-that-take-multiple-inputs-at-once/37323/18
*
* OpenProcessing.org/sketch/1593616
*/
import java.util.Map;
final Map<Integer, String> phs = new HashMap<Integer, String>();
static final int SHIFTS = 5;
static final String ERROR = " combo key not found!";
String phoneme = "Hold some keys & release them";
int heldKeys, keyShifts, prevKey;
void setup() {
size(400, 150);
noLoop();
fill(#FFFF00); // yellow
textSize(030);
textAlign(CENTER, CENTER);
createPhonemes();
println(phs);
println("Size: " + phs.size());
}
void draw() {
background(#0000FF); // blue
text(phoneme, width >> 1, height >> 1);
}
void keyPressed() {
if (keyCode != prevKey && checkAbcRange(keyCode)) {
heldKeys |= abc(prevKey = keyCode, keyShifts++);
println(key + "\t" + heldKeys + "\t" + keyShifts);
}
}
void keyReleased() {
if (heldKeys > 0) {
phoneme = phs.get(heldKeys);
if (phoneme == null) phoneme = heldKeys + ERROR;
heldKeys = keyShifts = prevKey = 0;
redraw();
}
}
static final boolean checkAbcRange(final int keyValue) {
return keyValue >= 'A' && keyValue <= 'Z';
}
static final int abc(final int keyValue) {
return abc(keyValue, 0); // no left-shiftings
}
static final int abc(final int keyValue, final int shifts) {
return keyValue - 'A' + 1 << shifts * SHIFTS; // range 1 to 26
}
See More Shortcuts