Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
Dim KC As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then KC = True
If KeyCode = KeyCodes.KEYCODE_HOME Then KC = True
If KeyCode = KeyCodes.KEYCODE_POWER Then KC = True
If KC = True Then 'if KC was true then one of the buttons that would close the app was pressed. Now we try to stop it from happening
If Msgbox2("Do you want to close?", "Exit?", "Yes", "", "No", Null) = DialogResponse.POSITIVE Then
Return False
Else
Return True
End If
End If
End Sub