PDA

View Full Version : onKeyPress Listener not getting fired in ie8 only



sharaf.satishkumar
11 Jan 2012, 1:39 AM
hi,
i have a grid with some columns.
i set tab index as 1 to the grid header and all the column header for navigating along the columns
and wrote addListener to header's x coulmn header as


getHeader().getHead(x).addListener(Events.OnKeyPress, new Listener()

and wrote code in side handle event

public void handleEvent(final BaseEvent be){

if( tab key is pressed)
{
// do some work
}

else if(arrow key is pressed){
//do some work
}

}

its working cool in fire fox 8.0.1 :)

but in ie8 the flow not even entering in the Listener.:s


please some one help me out...

sharaf.satishkumar
11 Jan 2012, 5:36 AM
i think my code is not clear please see this example

tabIndexForColumns()
{
final int numberOfCols = 9;
if (getHeader() != null)
{
getHeader().setTabIndex(1);
for (int i = 0; i < numberOfCols; i++)
{
if (getHeader().getHead(i) != null)
{


getHeader().getHead(i).setTabIndex(1);
getHeader().getHead(i).addListener(Events.OnKeyPress, new Listener()
{
@Override
public void handleEvent(final BaseEvent be)
{
if (((ComponentEvent) be).getKeyCode() == KeyCodes.KEY_TAB)
{
// code to be executed when tab key is
// pressed


}
else if (((ComponentEvent) be).getKeyCode() == KeyCodes.KEY_RIGHT)
{
// code to be executed when right arrow key
// is pressed
}
else if (((ComponentEvent) be).getKeyCode() == KeyCodes.KEY_LEFT)
{
// code to be executed when l key is pressed
}
}
});
}
}
}
}

this sample is working cool for fire fox 8. but flow is failing to go inside

getHeader().getHead(i).addListener(Events.OnKeyPress, new Listener()
{
@Override
public void handleEvent(final BaseEvent be)
{
if (((ComponentEvent) be).getKeyCode() == KeyCodes.KEY_TAB)
{
................................
...................
this listener.

i thinks its clear now.

smiletolead
18 Jan 2012, 3:35 AM
Hi Satish
The keys like arrow keys are considered as special keys. IE does not fire key press event on pressing these keys. Instead, it fires key down event. But the browsers such as firefox fire key press event, if the key pressing changes something in the browser. For example, pressing arrow key moves the cursor, pressing tab shifts the focus. So you need to use keydown event. You can refer this site for more details: http://www.quirksmode.org/dom/events/keys.html
(http://www.quirksmode.org/dom/events/keys.html)
Regards,
Ganesh