Simulate back/menu/search button clicks

99toLife

Member
Licensed User
Longtime User
After searching the forum I haven't found a way to simulate a back/menu/search button click. For example, I want a button in the app that brings up the same menu that the menu button brings up. I hope this makes sense and someone might have a suggestion or two. :sign0163:
 

hbruno

Member
Licensed User
Longtime User
You can use :

B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean 
   Dim Rep As Int
   Select KeyCode
      Case KeyCodes.KEYCODE_BACK  ' --> Button "BACK"

      Case KeyCodes.KEYCODE_SEARCH ' --> Button "SEARCH"

                          Case KeyCodes.KEYCODE_MENU ' --> Button "MENU"

   End Select
End Sub
And, in the program, when you want to simulate the Button SEARCH :

B4X:
Activity_KeyPress(KeyCodes.KEYCODE_SEARCH)
 
Upvote 0

99toLife

Member
Licensed User
Longtime User
Thanks for your help but I don't think I'm explaining it right. If I check for the menu button in Activity_KeyPress it will only consume it or not. What I want to do is invoke the menu that is shown by the menu button (without pressing the menu button). Returning true or false in Activity_KeyPress doesn't invoke it. :( Any other suggestions? Thanks again!
 
Last edited:
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
mmm. I Just realised that if you want back key on say to get rid of keboard
or anything else that pops up then my code won't work - it will close the entire activity.

I'm not sure if that's what you want.

regards, Ricky
 
Upvote 0

99toLife

Member
Licensed User
Longtime User
mmm. I Just realised that if you want back key on say to get rid of keboard
or anything else that pops up then my code won't work - it will close the entire activity.

I'm not sure if that's what you want.

regards, Ricky

I wanted to programmatically open the menu that is opened from the menu button. I appreciate knowing about Activity.Finish though. Thanks! :icon_clap:
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
Oh ok.

So why do you to also do the Back key? To close the menu? If so there's a CloseMenu method.

regards, Ricky
 
Upvote 0
Top