New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyPressed for multiple keys #5050

Merged
merged 1 commit into from May 5, 2017

Conversation

Projects
None yet
3 participants
@JakubValtar
Contributor

JakubValtar commented May 4, 2017

Java2D and FX2D send multiple PRESSED and only one RELEASE event (at
least on Windows). Therefore we have to keep track of what is pressed
and what not. Most keyboards do not support pressing more than ~10 keys
simultaneously, so this should not cause any performance problems.

See focusLost() for possible problem when user overrides it and does not call super. It's there only to clear keys when ALT+TAB is pressed so the chance somebody will hit this is low.

Fixes #5049

Fix keyPressed for multiple keys
Java2D and FX2D send multiple PRESSED and only one RELEASE event (at
least on Windows). Therefore we have to keep track of what is pressed
and what not. Most keyboards do not support pressing more than ~10 keys
simultaneously, so this should not cause any performance problems.

Fixes #5049

@benfry benfry merged commit a22af42 into processing:master May 5, 2017

@JakubValtar JakubValtar deleted the JakubValtar:fix-keypressed branch May 5, 2017

@GoToLoop

This comment has been minimized.

Show comment
Hide comment
@GoToLoop

GoToLoop Jun 4, 2017

Perhaps a HashSet<Long> would be a better fit than an ArrayList<Long> for field pressedKeys here:
http://docs.Oracle.com/javase/8/docs/api/java/util/HashSet.html

Using a Set instead, statement if (!pressedKeys.contains(hash)) pressedKeys.add(hash);
can be replaced by pressedKeys.add(hash); only; given a Set can't have duplicated elements after all.

Due to its hashable searching nature, a Set should be more performant when using methods such as contains(Object) & remove(Object) than a List.

GoToLoop commented Jun 4, 2017

Perhaps a HashSet<Long> would be a better fit than an ArrayList<Long> for field pressedKeys here:
http://docs.Oracle.com/javase/8/docs/api/java/util/HashSet.html

Using a Set instead, statement if (!pressedKeys.contains(hash)) pressedKeys.add(hash);
can be replaced by pressedKeys.add(hash); only; given a Set can't have duplicated elements after all.

Due to its hashable searching nature, a Set should be more performant when using methods such as contains(Object) & remove(Object) than a List.

@GoToLoop

This comment has been minimized.

Show comment
Hide comment
@GoToLoop

GoToLoop Jun 4, 2017

On the other hand, if the # of elements in the container pressedKeys is always small, I guess a List might be indeed faster than a Set in this case. O_o

GoToLoop commented Jun 4, 2017

On the other hand, if the # of elements in the container pressedKeys is always small, I guess a List might be indeed faster than a Set in this case. O_o

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment