Hi,
Sorry if this is the wrong place; I couldn't find a forum on hacks. This is regarding the multi-key press hack: http://www.processing.org/hacks/hacks:multiplekeys
I used the first example and it works MOST of the time. The problem comes when holding down many keys. It seems like if you hold down about 4 or 5 keys, it stops reading in the new presses until other keys are released. Here is an example I made to illustrate that:
Code:
PFont font;
void setup() {
size(200,200);
font = loadFont("ArialMT-12.vlw");
textFont(font,12);
stroke(255);
}
void draw(){
background(0);
checkKeys();
}
boolean[] keys = new boolean[526];
void checkKeys()
{
for(int i = 0; i < keys.length; i++)
if (keys[i] == true){
text(KeyEvent.getKeyText(i),(i*8)%width,int(i*8/width)*8 + 20);
}
}
void keyPressed()
{
keys[keyCode] = true;
println(KeyEvent.getKeyText(keyCode));
}
void keyReleased()
{
keys[keyCode] = false;
}
Try holding down many keys, 1 at a time and watch what happens.
I tried to fix this by using the second example which is supposedly "snappier". When I first ran the example I got "Cannot parse error text: C:\.....\HelloWorld.java is missing" I then converted this code into Processing code like this:
Code:
import bak.pcj.set.IntSet;
import bak.pcj.set.IntOpenHashSet;
IntSet keysheld;
void setup() {
IntSet = new IntOpenHashSet();
/**
* @param keycode key integer code, the value are constants defined in KeyEvent Class
* http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html
* e.g. KeyEvent.VK_A for letter A
* KeyEvent.VK_0 for number 0
* KeyEvent.VK_SHIFT for shift button
* @return true if the key is currently held down, false otherwise
*/
}
boolean checkKeysHeld(int keycode){
keysheld.contains(keycode);
}
void keyPressed(){
// add key to the list of keys held down
// with processing, the KeyEvent object is always available as "keyEvent",
// the getKeyChar() is already in the variable 'key', and getKeyCode() is in the variable 'keyCode'.
keysheld.add(keyEvent.getKeyCode());
println("key pressed: "+KeyEvent.getKeyText(keyEvent.getKeyCode()));
println("keys in current held list: "+keysheld.toString());
}
void keyReleased(){
// remove key from the list of keys held down
keysheld.remove(keyEvent.getKeyCode());
}
I now get the error "The package "bak" does not exist. You might be missing a library.
So I guess I have a few questions:
1. Why doesn't the first example work all the time?
2. The 2nd example seems to be Java code, I think. Should this compile in Processing? If (yes) {why doesn't it?} else {why did someone post it in the Processing hacks section?}
3.Where can I obtain the "bak" library to compile this code?
Sorry this was loooong, but more information is better than less right?