View Full Version : What's the best way of trapping keyboard input?

29 Nov 2009, 8:53 AM
I have a panel in a window which when active (eg mouse is inside the area), I'd
like to capture all keypress input - eg everything .

I'm just wondering what the best way to do this in Ext, so after the mouse moves
out of the panel, normal behaviour is returned.



1 Dec 2009, 6:21 AM
use mouse events, and then use disabled = true.

5 Dec 2009, 12:05 PM
I'm not sure what you mean with disabled=true?

In my BoxComponent I can trap 'mouse over' and what I'd like to
do is then something like

document.onKeyUp = processKey

ie direct all document key input to some function. When the mouse
moves out of the BoxComponent I'd like to revert to normal behaviour.

This is for a game type application where you need to control an
object with cursor keys. The game appears as HTML inside a
BoxComponent and works great with a mouse, but I get no response
to the keyboard (because its not a form or text object).

6 Dec 2009, 12:45 AM
Some DOM element has to have focus for keyboard events to be available.

Use the mouseenter event on the Window's getEl() (It has to be rendered for you to add this listener) to focus the Window (Window has a hidden <a> which can hold focus)

Then use http://www.extjs.com/deploy/dev/docs/?class=Ext.Panel&member=keys