Hallo,
i've tried onKeyUp, onKeyDown and onBackPressed, and dispatchKeyEvent to handle the back soft key, all the methods received the signal and I could handle it, but seems like android itself still handled the key which lead to exit the application after my code. Any hints? Best regards Andreas |
Administrator
|
On 05/14/2014 11:31 PM, Andreas Drewke [via jogamp] wrote:
> Hallo, > > i've tried onKeyUp, onKeyDown and onBackPressed, and dispatchKeyEvent to > handle the back soft key, > all the methods received the signal and I could handle it, but seems like > android itself still handled the key which lead to exit the application after > my code. We intercept Android KeyEvent.KEYCODE_BACK here: <http://jogamp.org/git/?p=jogl.git;a=blob;f=src/newt/classes/jogamp/newt/driver/android/WindowDriver.java;h=9af455445a6ff77df1a6ab0ee21f3469469c8d9d;hb=HEAD#l693> .. handle it in handleKeyCodeBack(): <http://jogamp.org/git/?p=jogl.git;a=blob;f=src/newt/classes/jogamp/newt/driver/android/WindowDriver.java;h=9af455445a6ff77df1a6ab0ee21f3469469c8d9d;hb=HEAD#l627> Here it sends an KeyEvent.VK_KEYBOARD_INVISIBLE in case the soft-keyboard is assumed visible, otherwise KeyEvent.VK_ESCAPE is sent. KeyEvent.VK_ESCAPE and KeyEvent.VK_HOME (both release) is handled here only if not yet consumed by the user! <http://jogamp.org/git/?p=jogl.git;a=blob;f=src/newt/classes/jogamp/newt/driver/android/WindowDriver.java;h=9af455445a6ff77df1a6ab0ee21f3469469c8d9d;hb=HEAD#l652> - KeyEvent.VK_ESCAPE finishes the activity - KeyEvent.VK_HOME triggers going to 'home', which activity is still active Note: If you like to avoid finishing the activity, all you need is to intercept KeyEvent.VK_ESCAPE (key release) in your consumeKeyEvent(..) override of your NEWT KeyListener and mark the event consumed. +++ The above behavior is documented here: - <https://jogamp.org/bugzilla/show_bug.cgi?id=677#c4> - <http://jogamp.org/git/?p=jogl.git;a=commit;h=3a4892c43be4a9dabba73d42175c2cfa39bd6d8d> - <http://jogamp.org/git/?p=jogl.git;a=commit;h=58ebd43a78491281e2c3b012666220ed47634c7e> - <http://jogamp.org/git/?p=jogl.git;a=commit;h=8b34a0389e07967ce0c2ccc430a7c1d0803c3e51> Then we even add support to 'pause' the GLContext and it's resource when 'homing' (home button) - <http://jogamp.org/git/?p=jogl.git;a=commit;h=d514ecbf052d013ea8c0982c490757678075a9ea> ~Sven > > Any hints? > > Best regards > Andreas signature.asc (894 bytes) Download Attachment |
My KeyListener interface is the following:
// Compiled from KeyListener.java (version 1.6 : 50.0, no super bit) public abstract interface com.jogamp.newt.event.KeyListener extends com.jogamp.newt.event.NEWTEventListener { // Method descriptor #5 (Lcom/jogamp/newt/event/KeyEvent;)V public abstract void keyPressed(com.jogamp.newt.event.KeyEvent arg0); // Method descriptor #5 (Lcom/jogamp/newt/event/KeyEvent;)V public abstract void keyReleased(com.jogamp.newt.event.KeyEvent arg0); } So there is no consumeKeyEvent(..) And the following does not work as well for HOME soft key, but work for other keys. public class XYZ implements GLEventListener, KeyListener, WindowListener { ... /* * (non-Javadoc) * @see com.jogamp.newt.event.KeyListener#keyReleased(com.jogamp.newt.event.KeyEvent) */ public void keyReleased(com.jogamp.newt.event.KeyEvent event) { if (gameTickThread == null) return; if (event.isAutoRepeat() == true) return; // int keyCode = event.getKeyCode(); boolean keyConsumed = false; if (keyCode == KeyEvent.VK_ESCAPE) { gameTickThread.setKeyEscape(); keyConsumed = true; } .. // event.setConsumed(keyConsumed); } I am using JOGL 2.1.5 Any help would be great. Thank you!!! |
Administrator
|
On 05/15/2014 11:41 AM, Andreas Drewke [via jogamp] wrote:
> So there is no consumeKeyEvent(..) yeah, you found it 'setConsumed(boolean)' > > And the following does not work as well for HOME soft key, but work for other > keys. So it works for the soft-back, i.e. ESCAPE' as described I assume. Indeed, we don't capture HOME, since we don't want to allow 'stealing' the device. ~Sven signature.asc (894 bytes) Download Attachment |
Administrator
|
In reply to this post by Andreas Drewke
On 05/15/2014 10:17 PM, Sven Gothel wrote:
> On 05/15/2014 11:41 AM, Andreas Drewke [via jogamp] wrote: >> So there is no consumeKeyEvent(..) > yeah, you found it 'setConsumed(boolean)' > >> >> And the following does not work as well for HOME soft key, but work for other >> keys. > > So it works for the soft-back, i.e. ESCAPE' as described I assume. > > Indeed, we don't capture HOME, since we don't want to allow 'stealing' the device. > I guess we would need to override an Android method like we do for the 'soft back' 'onKeyPreIme(..)' .. We may discuss this issue .. i.e. add an enhancement bug report and maybe a patch .. However, we have also consider the security aspect, i.e. 'stealing' the device, a.k.a blocking it with your application. > ~Sven > signature.asc (894 bytes) Download Attachment |
Hallo,
you are completely right. Consuming the VK_ESCAPE Event in key release method works 100%. Sorry. I just made a small mistake. Thank you. Best regards Andreas |
Free forum by Nabble | Edit this page |