Detect button pressed

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Tymski
New User
Posts: 4
Joined: Thu May 12, 2016 3:58 pm

Detect button pressed

Postby Tymski » Fri Jun 03, 2016 3:47 pm

hello!
I used:

int button = 0;
Button.waitForAnyPress();
button = Button.readButtons();


but when I press button fast I get 0. I need to hold a button for a second to get the correct ID. How can I improve it so even short press returns correct value?

User avatar
gloomyandy
leJOS Team Member
Posts: 6047
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Detect button pressed

Postby gloomyandy » Fri Jun 03, 2016 4:21 pm

Firstly I have moved your post to a different section. Please do not post questions about using leJOS in the development section that is intended to be used to discus the development of leJOS itself.

As to your question, why are you using both waitForAnyPress and readButtons? This is probably not a good idea. waitForAnyPress returns the state of the buttons after the button is pressed and so you can use this return value directly. Note however that as stated in the documentation. If the button is still down when you call this method then you will have to wait for it to be released before a new press will be detected. This means that you may need to ensure that the key has been released before you call waitForAnyPress again.

Perhaps if you provide details of exactly what it is you are trying to do we can offer a better solution.
leJOS news https://lejosnews.wordpress.com/

Tymski
New User
Posts: 4
Joined: Thu May 12, 2016 3:58 pm

Re: Detect button pressed

Postby Tymski » Fri Jun 03, 2016 8:41 pm

Oh, sorry, my bad. :oops: :oops:
I'm a noobie.


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest