How to perform KeyDown Event on canvas object??

94 views
Skip to first unread message

sunil

unread,
Dec 1, 2011, 7:20:05 AM12/1/11
to GWT Graphics
Hi,

I want to delete object from canvas if press "DELETE" key from
keyboard, how to do this. I tried but it seems not working . i have
attached piece of code , please help me on that.

rectangle.addDomHandler(new KeyDownHandler() {

@Override
public void onKeyDown(KeyDownEvent event) {
if(event.getNativeKeyCode()==KeyCodes.KEY_ENTER)
Window.alert("Rectangle Clicked");

}
},KeyDownEvent.getType());

Jovan Perovic

unread,
Dec 1, 2011, 8:08:41 AM12/1/11
to gwt-gr...@googlegroups.com
I think you'll have to wrap the whole canvas with FocusPanel which can receive key events. However, this way, you'll need to mark selected objects somehow (e.g. separate class FocusableRactangle that extends Rectangle) in order to known which object are to be deleted within keyDown event.

Maybe there is another way, but I'm sure this one will work...

Henri Kerola

unread,
Dec 1, 2011, 8:26:44 AM12/1/11
to gwt-gr...@googlegroups.com
I would take the same approach as Jovan suggests.

-Henri

$unil

unread,
Dec 1, 2011, 8:42:46 AM12/1/11
to gwt-gr...@googlegroups.com
I tried but m not able to solve ,  could you please provide me the sample code.

--
Thanks & Regards
Sunil Khanna
Mob -  +91 7387425988

 My Believe--
"The future belongs to those who believe in the beauty of their Dreams"
                         $Thought Become Things$

$unil

unread,
Dec 1, 2011, 8:53:20 AM12/1/11
to gwt-gr...@googlegroups.com
plz provide me the samplee

sunil

unread,
Dec 2, 2011, 12:47:00 AM12/2/11
to GWT Graphics

It'll be good for me if you guys provide me the sample... i tried
according to whatever u have mentioned in your mail, but there is an
error comes.

On Dec 1, 6:53 pm, "$unil" <er.sunilkha...@gmail.com> wrote:
> *plz provide me the samplee*
>
>
>
>
>
>
>
>
>
> On Thu, Dec 1, 2011 at 7:12 PM, $unil <er.sunilkha...@gmail.com> wrote:
> > *I tried but m not able to solve ,  could you please provide me the
> > sample code.*


>
> > On Thu, Dec 1, 2011 at 6:38 PM, Jovan Perovic <j.perovi...@gmail.com>wrote:
>
> >> I think you'll have to wrap the whole canvas with FocusPanel which can
> >> receive key events. However, this way, you'll need to mark selected objects
> >> somehow (e.g. separate class FocusableRactangle that extends Rectangle) in
> >> order to known which object are to be deleted within keyDown event.
>
> >> Maybe there is another way, but I'm sure this one will work...
>

> >> On Thu, Dec 1, 2011 at 1:20 PM, sunil <er.sunilkha...@gmail.com> wrote:
>
> >>> Hi,
>
> >>> I want to delete object from canvas if press "DELETE" key from
> >>> keyboard, how to do this. I tried but it seems not working . i have
> >>> attached piece of code , please help me on that.
>
> >>> rectangle.addDomHandler(new KeyDownHandler() {
>
> >>>                        @Override
> >>>                        public void onKeyDown(KeyDownEvent event) {
>
> >>>  if(event.getNativeKeyCode()==KeyCodes.KEY_ENTER)
> >>>                                        Window.alert("Rectangle Clicked");
>
> >>>                        }
> >>>                },KeyDownEvent.getType());
>
> > --

> > *Thanks & Regards*


> > Sunil Khanna
> > Mob -  +91 7387425988
>

> > * My Believe--*
> > *"The future belongs to those who believe in the beauty of their Dreams*"
> > *                         $Thought Become Things*$
>
> --
> *Thanks & Regards*


> Sunil Khanna
> Mob -  +91 7387425988
>

> * My Believe--*
> *"The future belongs to those who believe in the beauty of their Dreams*"
> *                         $Thought Become Things*$

Jovan Perovic

unread,
Dec 2, 2011, 5:52:08 PM12/2/11
to gwt-gr...@googlegroups.com
Hey sunil,

I'm pretty sure it can be done, however, I currently don't have my development environment set up here. I'll try to write an example during the weekend...

$unil

unread,
Dec 3, 2011, 2:12:54 AM12/3/11
to gwt-gr...@googlegroups.com
ok thanks,
--
Thanks & Regards
Sunil Khanna
Mob -  +91 7387425988

 My Believe--

"The future belongs to those who believe in the beauty of their Dreams"
                         $Thought Become Things$

Reply all
Reply to author
Forward
0 new messages