Vid,
Thanks very much for the reply.
I made the following example. It can either capture keyboard
events no matter what has the focus, or only if a focusPanel has the
focus, depending on the last line in onLoad()..
It captures everything on Firefox 8
It captures everything except ^W, ^T and ^N on chrome v15
It captures everything except ^P, ^O, and ^H on IE 8
I am coming to the conclusion that we really cannot capture all the
control keys on Chrome and IE.
Anyway, here is the source to my keyboard capture example:
package bi.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Event.NativePreviewEvent;
import com.google.gwt.user.client.Event.NativePreviewHandler;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class GwtKeyCapture extends FocusPanel
implements EntryPoint
{
private static HandlerRegistration
g_nativePreviewHandlerRegistration=null;
private static void captureKeyboard(
GwtKeyCapture mainPanel)
{
g_nativePreviewHandlerRegistration =
Event.addNativePreviewHandler(
mainPanel.new MyNativePreviewHandler());
}
private class MyNativePreviewHandler
implements NativePreviewHandler
{
@Override
public void onPreviewNativeEvent(NativePreviewEvent
previewEvt)
{
NativeEvent ne = previewEvt.getNativeEvent();
GWT.log("OnPrevEvt: " + ne.getType());
if( ne.getType().equalsIgnoreCase("keydown") ||
ne.getType().equalsIgnoreCase("keyup") ||
ne.getType().equalsIgnoreCase("keypress") )
{
m_strNEH = "OnPrev evt: " + ne.getType() +
" keycode: 0x" + I
nteger.toString(ne.getKeyCode(), 16);
m_lbl.setText( m_strBE + " | " + m_strNEH);
ne.preventDefault();
previewEvt.consume();
}
}
}
private String m_strBE="";
private String m_strNEH="";
Label m_lbl;
@Override
public void onBrowserEvent(Event event)
{
boolean isKeyEvent =
(event.getTypeInt() == Event.ONKEYDOWN) ||
(event.getTypeInt() == Event.ONKEYUP) ||
(event.getTypeInt() == Event.ONKEYPRESS);
if(isKeyEvent)
{
m_strBE = "onBE: " + event.getType() +
" keycode: 0x" +
Integer.toString(event.getKeyCode(), 16);
m_lbl.setText( m_strBE + " | " + m_strNEH);
GWT.log(m_strBE);
event.preventDefault();
} else
{
GWT.log("onBE: " + event.getType());
}
}
public void onModuleLoad()
{
m_lbl = new Label("Hello, GWT!");
add(m_lbl);
setSize("500px", "300px");
addStyleName("panelColor");
RootPanel.get().add(this);
sinkEvents(Event.KEYEVENTS);
/* NOTE: uncommenting next line
* allows capture even
* if focus panel doesn't have focus. */
captureKeyboard(this);
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.