[android-developers] Re: Events on GLSurfaceView
/**
196 * This inner class is used to monitor key events.
197 */
198 private class KeyListener implements View.OnKeyListener
199 {
200 public ArrayList<KeyEvent> currentEvents = new
ArrayList<KeyEvent>();
201 public ArrayList<KeyEvent> pendingEvents = new
ArrayList<KeyEvent>();
202
203 public boolean onKey(View view, int i, KeyEvent event)
204 {
205 synchronized (InputStage.this)
206 {
207 pendingEvents.add(event);
208 }
209 return true;
210 }
211 }
Have you thrown a debug log statement at line 205, there? I'd be
surprised if you didn't see that method being called on key presses.
If you always return true like that, you are telling the input stack
that you are consuming and handling all of the key events yourself,
which is why you keep losing your default keys (back, menu). You only
want to return true for keys that the game will use. Consider setting
up a binding system where the game binds to keys. Keep the list of
bound keys and only return true if the key event is for one of those
keys.
I never register a keylistener the way you are doing, though. I
always override onKeyDown and onKeyUp in my view subclass. Your way
should work as well. but I've never used it. I do know that a view
needs focus to handle events, which is why I keep telling you to make
sure you're setting the view as focusable.
On Jan 17, 4:59 pm, Peter Eastman <peter.east...@gmail.com> wrote:
> Here is where I create and add the listener:
>
> http://gamine.svn.sourceforge.net/viewvc/gamine/trunk/src/net/sf/gami...
>
> It gets added in onStart(), which is called from the start() method of
>
> http://gamine.svn.sourceforge.net/viewvc/gamine/trunk/src/net/sf/gami...
>
> I just tested calling setFocusable(true) again to be sure. As before:
> I still don't get key events, and the Back and Menu buttons stop
> working.
>
> If at all possible, I'd really prefer not to do event handling at the
> Activity level. This is a library (a 3D game engine), and I don't
> want to restrict how developers create their Activities. They just
> need to provide a suitable View for the library to work with.
>
> Peter
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home