Code to Check if a Button is Up

Fixx42

Member
Licensed User
Longtime User
Hello all,

I am trying to create an app to test one's reflexes. As part of it, I would like to add a piece of code that will check to see if a button is being pressed. In this situation, putting the code into Sub Button_Up doesn't work, since that part of the program doesn't run until after my reflex-tester program finishes. I took a shot in the dark and tried the following, but it didn't work. Any suggestions would be much appreciated!

If Button1.Up = 1 Then
Button1.Text = "early"​
Else
Button1.Text = "late"​
End If
 

Ricky D

Well-Known Member
Licensed User
Longtime User
try this

create the button and create it's up event handler also create it's down handler

B4X:
Sub Button1_Up
'early
    Button1.Text = "early"
End Sub

Sub Button1_Down
'late
    Button1.Text = "late"
End Sub

I haven't tried this but that's the only way I know to catch the up or down of a button.

regards, Ricky
 
Upvote 0

Fixx42

Member
Licensed User
Longtime User
Thanks for the advice Ricky, that's the method that I was hoping to use, but it seems that it isn't working for me for this use case. Sorry, I probably should have explained more.

Basically, I am running a program where the user presses down on a button, the program waits for 5 seconds, marks the current time, and then it beeps. After the program beeps, the user is supposed to remove their finger as quickly as possible. When the button is released, the the Sub Button1_Up process subtracts that marked pre-beep time from the current time to find how long of a delay there was between the beep and the release of the button.

It seems to work great under normal use, but I'm running into a problem where - if the user removes their finger early - that Button1_Up process doesn't get triggered until after the reflex-test program has run its course and beeped. So, instead of telling the user that they removed their finger early, it tells them that their delay was only 90 ms or so.

To fix this, I'm hoping to find a way to check if the button is being pressed immediately before the app beeps. Then, if it turns out the button isn't being pressed, the app will report that the user was early, instead of spitting out a time.

Again, sorry for not being clearer, and thank you for your reply!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…