Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to lock a device "back" button?
Started by stalxerhd Jan 14 2020 12:26 AM

3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

stalxerhd

[GLOBAL: userInfoPane.html]
stalxerhd
  • Observer

  • 23 posts
  • Corona SDK

I added a few transitional scenes between the main levels, nothing special happens on them, but if press the physical button "back" on the device (or emulate), the game will crash or close.

 

To prevent this on the main levels, I set everywhere with differen actions:

function onKeyEvent( event )
-- Some Code Here
end

For example, on the menu.lua level I have the question "exit: yes/no".

 

But at transitional scenes, I do not need special actions. Is there a way to block or ignore commands from this button?

 

How do you prevent physical keys in short transitional scenes 10-120 seconds long?

 

 



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Corona Geek

  • 1,103 posts
  • Corona SDK

The easiest approach is to have a conditional check in your key event function. If the check fails, i.e. canExit is false, then if back button is pressed, it'll just be captured but ignored by Corona.

local canExit = false

local function onKeyEvent( event )

	if canExit then
		-- Your "exit game" code
	else
		if keyName == "back" then
			return true
		else
			return false
		end
	end
	
	return false
end

  • roaminggamer and stalxerhd like this

[TOPIC: post.html]
#3

stalxerhd

[GLOBAL: userInfoPane.html]
stalxerhd
  • Observer

  • 23 posts
  • Corona SDK

Thanks for advice! I will try it soon.



[TOPIC: post.html]
#4

bilalawan8111

[GLOBAL: userInfoPane.html]
bilalawan8111
  • Observer

  • 3 posts
  • Corona SDK

  1. if (Application.platform == RuntimePlatform.Android)
  2.         {
  3.             if (Input.GetKey(KeyCode.Escape))
  4.             {
  5.                 // Insert Code Here (I.E. Load Scene, Etc)
  6.                 // OR Application.Quit();
  7.  
  8.                 return;
  9.             }  //this the way to program the back button.hope it will solve your issue.❤️
     



[topic_controls]
[/topic_controls]