Ah, I see that most of the keys work fine, but dpad directional keys
only show a key release the first time. I'd guess maybe it has
something to do with the dpad trying to change which component has
focus while in touch view. Unfortunately I could not find a way to fix
this. Can you work around it?

On Mar 24, 3:52 am, hanni <[EMAIL PROTECTED]> wrote:
> Here's a simple example with only an Activity and a View. If you press
> the pointer and then the dpad-down key. You will see the following
> output:
>
> Pointer pressed
> Pointer released
> Key released: 20
>
> where the key pressed callback is missing. If you then press the dpad-
> down again, you will get
>
> Key pressed:  20
> Key released: 20
>
> which is the desired behavior.
>
> public class MyActivity extends Activity
> {
>     public void onCreate(Bundle icicle)
>     {
>         super.onCreate(icicle);
>         setContentView(new MyView(this));
>     }
>
>     public class MyView extends View
>     {
>         public MyView(Context context)
>         {
>             super(context);
>
>             setFocusable(true);
>             setFocusableInTouchMode(true);
>         }
>
>         public boolean onKeyDown(int keyCode, KeyEvent event)
>         {
>             Log.i("test", "Key pressed:  " + keyCode);
>             return true;
>         }
>
>         public boolean onKeyUp(int keyCode, KeyEvent event)
>         {
>             Log.i("test", "Key released: " + keyCode);
>             return true;
>         }
>
>         public boolean onTouchEvent(MotionEvent event)
>         {
>             switch (event.getAction())
>             {
>                 case MotionEvent.ACTION_DOWN:
>                     Log.i("test", "Pointer pressed");
>                 break;
>                 case MotionEvent.ACTION_UP:
>                     Log.i("test", "Pointer released");
>                 break;
>             }
>             return true;
>         }
>     }
>
> }
>
> On 23 Mar, 20:35, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > I'm not sure why this isn't working. Can you post some example code
> > that shows it not working?
>
> > On Mar 23, 2:11 am, hanni <[EMAIL PROTECTED]> wrote:
>
> > > Thanks for the suggestion Dan!
>
> > > I tried implementing the OnKeyListener, but it received the same key
> > > events as View.onKeyDown()/Up() and View.dispatchKeyEvent(). (That is,
> > > the key down event from pressing a key just after using the pointer,
> > > is suppressed, but I do get the key up event when releasing it.)
>
> > > I have double-checked that the the View is indeed focused when the key
> > > event comes in.
>
> > > It seems that I either need to have a way to programmatically switch
> > > to key mode after each pointer press...
> > > ...Or that I need to find some other method to override, before
> > > Android has decided to suppress the key down event. (It's strange that
> > > the key up event still is let through.)
>
> > > On 22 Mar, 21:09, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > I helped someone out with this very problem a few days ago, but it
> > > > looks like you already tried the solution and it didn't work for you.
> > > > The fix was this combination when the view was created:
>
> > > >         setFocusable(true);
> > > >         setFocusableInTouchMode(true);
>
> > > > Do you know for sure that the view you have is focused when you are in
> > > > touch mode and try to press a key?
>
> > > > I think there is a setOnKeyListener method. Not sure if it'd help, but
> > > > you might try experimenting with it.
>
> > > > On Mar 22, 4:27 am, hanni <[EMAIL PROTECTED]> wrote:
>
> > > > > Hi, ever since the M5 version of the SDK there is a concept of a
> > > > > "touch mode". Whenever you click or drag with the pointer in an
> > > > > application, it automatically goes into this mode.
>
> > > > > The problem in my application comes when I want to press a key, after
> > > > > using the pointer for something. The first time I press a key, when in
> > > > > touch mode, I do not get a onKeyDown()-callback. Instead the
> > > > > application is now put into key mode, so that all following keypresses
> > > > > is registered correctly, until I use the pointer again.
>
> > > > > My application is basically a single View, where both keys and pointer
> > > > > should be used freely.
> > > > > I have tried the following things in order to avoid missing that one
> > > > > special onKeyDown()-callback right after using the pointer:
>
> > > > >   *  All possible combinations of View.setFocusable(true/false) and
> > > > > View.setFocusableInTouchMode(true/false) inside my View.
>
> > > > >   *  Overriding View.dispatchKeyEvent() in order to see if I could get
> > > > > the 'key down' event in there somehow, but with no luck. (I do,
> > > > > however get the 'key up' event when I release the key, but that does
> > > > > not help my case.)
>
> > > > >   *  Tried to programmatically inject a key event after each time the
> > > > > pointer is used, to automatically switch back to key mode. While this
> > > > > works, unfortunately it takes the emulator about two seconds to
> > > > > actually do the inject, which makes everything freeze for two seconds
> > > > > after each pointer press.
>
> > > > > Is there any other workaround to automatically get back into key mode
> > > > > after the pointer is pressed, or any other way you guys can think of
> > > > > in order to have the same behavior?
>
> > > > > Big thanks- Dölj citerad text -
>
> > > > - Visa citerad text -- Dölj citerad text -
>
> > - Visa citerad text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to