Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
question about the return value of keydown event — Gideros Forum

question about the return value of keydown event

alexzhengalexzheng Guru
edited August 2013 in General questions
This is the method handle the keydown event in java.
public boolean onKeyDown(int keyCode, KeyEvent event)
{
GiderosApplication app = GiderosApplication.getInstance();

if (app != null && app.onKeyDown(keyCode, event) == true)
return true;

//I want to add my back handler here if the return value is false in lua code

return super.onKeyDown(keyCode, event);
}

is app.onKeyDown always return true for back key, can I determined it in the keydown event listener of lua code?

For example, in some scene I will handle the back keydown event in lua, but in main menu scene I will just handle it in this java method.


stage:addEventListener(Event.KEY_DOWN, function()
if event.keyCode == KeyCode.BACK then
return false ---then app.onKeyDown in java will return false
end
end)

Comments

  • @alexzheng there is no way to know if you will use back key in lua or not at that point of execution, thus I think app.onKeyDown(keyCode, event) always returns true.

    But it depends on the purpose you want to use button in java.
    For example you can do something like:
    <a href="http://forum.gideros.rocks/profile/Override" rel="nofollow">@Override</a>
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
    	//check if you need the back button here
    	if(you need it)
    	{
    		//do what you need
    		return true;
    	}
    	//else let Gideros handle button in lua
    	GiderosApplication app = GiderosApplication.getInstance();
    	if (app != null && app.onKeyDown(keyCode, event) == true)
    		return true;
     
    	return super.onKeyDown(keyCode, event);
    }
  • that was what I did currently,but that is not what I want,I want to do something depend on the return value
  • atilimatilim Maintainer
    It's not possible to get a return value because key events are put in a queue and processed later.
Sign In or Register to comment.