openframeworks / openframeworks/openFrameworks
of*Window/ofEvents: pressedKeys accumulate in special cases
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
In some cases, when modifier keys are used, the pressedKeys set will accumulate keys.
This happens because "modifier-up" messages are not sent in the same way as normal and special keys.
To test, watch the size of the pressedKeys:
cout << pressedKeys.size() << " num pressed keys " << endl;
Press a modifier key and a normal key -- say ctrl-a. If the 'a' is lifted first, then the modified-a key int is removed from the pressedKeys set. If CTRL is released before the 'a', then the non-modified-a key-up int is sent, and it is not erased from the pressedKeys set. If this is repeated with different modifier+key downs / ups the accumulation occurs.
Ultimately, there needs to be better handling of modifier keys. Perhaps there is a way to use the modifier masks keep track of modifier keys with a call to glutGetModifiers() in the keyboard_cb and keyboard_up_cb static methods?
It looks like progress has been made toward this in ofConstants.h
#define OF_KEY_CTRL 0x0200
#define OF_KEY_ALT 0x0300
#define OF_KEY_SHIFT 0x0400
But it seems to have stopped there.
I'm happy to work on this -- any suggestions on a strategy? Perhaps this is already being addressed of 007?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing pressedKeys handling through of*Window/ofEvents and the static keyboard_cb and keyboard_up_cb methods, then inspect the modifier constants in ofConstants.h. Reproduce the ctrl-a cases described, including releasing CTRL before A. Done means modifier and normal key-up events remove the correct entries without accumulation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100