onKeyPressed() vs. ofGetKeyPressed()

I just realized today that testing keys with onKeyPressed()/onKeyReleased() and keeping track of them with booleans sometimes results in keys getting “stuck”. This is especially apparent in WASD-style programs. In the logs what I actually see is that sometimes the keyPressed message arrives but the keyReleased message never does. I just switched over to testing ofGetKeyPressed() in my main update loop and the problem is gone. It’s like magic!

What would explain the difference in the behavior here?

I am really curious to know because there are a few keyboard piano apps (nanostudio) that suffer the same stuck-key problem and I would love to see that fixed. Maybe this info could help?

Not sure if it’s related, but perhaps a combination of https://github.com/openframeworks/openFrameworks/issues/652 and N-Key Rollover issues?

1 Like

i did read that post, but it seems that i have the problem even without modifiers. n-key rollover makes sense, but that seems like it would be a operating system/keyboard driver issue whereas i am able to “fix” the problem by using ofGetKeyPressed() instead of onKeyPressed(). ill check out the source, maybe i can puzzle out the difference.