Help please. In the following code I want to change the value of varH and so the color of the letter H once and only once. So, when the H or h key is pressed the value of varH should increase by 1. If the key is kept pressed down the value of varH should not keep increasing.
If the key is released and then pressed again, the value of varH should increase (just) once again.
If this is an operating system problem, is there a work-around?
This is what the reference states about how keyPressed() works:
" Because of how operating systems handle key repeats, holding down a key may cause multiple calls to keyPressed() ."
So you might have to work around this problem by manually keeping track, if your key was released inbetween differen key-events.
With the P2D / P3D renderer key repeat is disabled by default. You can change the renderer by adding P2D to the size call in your setup / settings method: size(yourWidth, yourHeight, P2D);
Technical background:
JavaDocs hint(ENABLE_KEY_REPEAT)
hint(ENABLE_KEY_REPEAT) - Auto-repeating key events are discarded by default (works only in P2D/P3D); use this hint to get all the key events (including auto-repeated).
Call hint(DISABLE_KEY_REPEAT) to get events only when the key goes physically up or down.