Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    Right sort of idea, but I don't this is going to work since there are two buttons and releaseKey() doesn't seem like it will distinguish. So probably the un-pushed button will immediately undo the pushed one, preventing any improvement. I'm not sure if the problem can be solved with shared "had anything been pushed?" tracking or if the key states will need to be tracked and released independently. Commented Jan 9, 2017 at 23:17
  • Perhaps things might be simplified by writing the code so that if one button is pushed the other gets ignored, but the code will need to be sure to release any pushed button before it indicates the push of another. Commented Jan 9, 2017 at 23:18
  • Just asking, why not using "while-loop" instead? Commented Jan 10, 2017 at 2:19
  • @ChrisStratton good point. Changed it so it only send press or release when the button state has changed. That doesn't handle pressing multiple buttons at the same time, but keeps it simple enough to understand. Commented Jan 10, 2017 at 11:01
  • @dhimaspw A while loop would block any other code. So that will work for this simple sketch, but will cause issues if you ever want to add additional code. Like for example pressing multiple buttons at the same time. Commented Jan 10, 2017 at 11:03