tags:

views:

188

answers:

2

Is it possible to capture keyboard events within a diagram produced using Dojox.GFX?

We have a simple graphical application which involves some shapes drawn on a surface. We would like to add some simple keyboard interaction, e.g. using the Delete key to delete a shape, and using "Ctrl+A" to select all shapes.

I have tried adding dojo.connect and shape.connect statements for "onkeypress" and "onkeyup", but they never seem to get triggered. We are already capturing mouse events and these are working fine.

Thanks

David

A: 

Keyboard events are not pointed, they are essentially global. You should catch them globally attaching a handler to document or body.

Eugene Lazutkin
A: 

Thanks, now working!

In my case this was a portlet so the <body> tag was not available, but I used a <div> tag instead:

<div id="queryPortlet" onkeydown="handleKeydown(event.keyCode);" onkeyup="handleKeyup(event.keyCode);">

The other thing I had to watch for was not intercepting keystrokes if the focus was in a text input field. I had to write some code to keep track of when the focus was in a text field, by adding onfocus() and onblur() handlers to all such fields. This was a slight pain but was the only way I could find to do that.

David E