Skip to content

Commit f2b5ed0

Browse files
committed
Add B4XPage_KeyPress for B4A
1 parent 12b6d04 commit f2b5ed0

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

B4A/$APPNAME$.b4a

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ Sub Activity_ActionBarHomeClick
5151
End Sub
5252

5353
Sub Activity_KeyPress (KeyCode As Int) As Boolean
54-
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
54+
If KeyCode = KeyCodes.KEYCODE_BACK Then
55+
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
56+
End If
57+
B4XPages.GetManager.RaiseEvent(B4XPages.GetManager.GetTopPage, "B4XPage_KeyPress", Array(KeyCode))
58+
Return False
5559
End Sub
5660

5761
Sub Activity_Resume

B4A/Objects/res/drawable/icon.png

5.31 KB
Loading

B4XMainPage.bas

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,27 @@ End Sub
3131

3232
Private Sub Button1_Click
3333
xui.MsgboxAsync("Hello world!", "B4X")
34-
End Sub
34+
End Sub
35+
36+
#If B4A
37+
Private Sub B4XPage_KeyPress (KeyCode As Int) As Boolean 'ignore
38+
Select KeyCode
39+
Case KeyCodes.KEYCODE_BACK
40+
'code to handle back key
41+
Case KeyCodes.KEYCODE_VOLUME_DOWN, KeyCodes.KEYCODE_VOLUME_UP
42+
'code to handle volume keys
43+
Case KeyCodes.KEYCODE_MEDIA_PLAY_PAUSE
44+
'code to handle media button
45+
Case Else
46+
Return False 'Pass to Android System
47+
End Select
48+
End Sub
49+
50+
Private Sub B4XPage_CloseRequest As ResumableSub
51+
'If Drawer.LeftOpen Then
52+
' Drawer.LeftOpen = False
53+
' Return False
54+
'End If
55+
Return True
56+
End Sub
57+
#End If

0 commit comments

Comments
 (0)