+ "applications. (see our article on <a href=\"http://www.itmill"
+ ".com/articles/Keybindings_in_Web_Browsers.htm\">"
+ "www.itmill.com)</a></p>"
- + "Events are attached to Window in this application, so a "
- + "component inside window must be focused to fire event on"
- + " keyboard shortcut.</p>"
+ + "<p>Focus must be inside web application (eg. not in address "
+ + "bar) for shortcuts to work. By default app element is focused.</p>"
+ "<strong>Shortcuts used in this example:</strong> "
+ "<br/>ESC restarts program, ctrl-shift-a (Button A), "
+ "ctrl-shift-z (Button Z), ctrl-shift-x (Button X)",
w.addActionHandler(this);
- f.focus();
}
public Action[] getActions(Object target, Object sender) {
import java.util.Iterator;
import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
public IView(String elementId) {
super();
setStyleName(CLASSNAME);
+
DOM.sinkEvents(getElement(), Event.ONKEYDOWN);
+ DOM.setElementPropertyInt(getElement(), "tabIndex", 0);
+
RootPanel.get(elementId).add(this);
Window.addWindowResizeListener(this);
+
+ // set focus to iview element by default to listen possible keyboard
+ // shortcuts
+ focus(getElement());
+
}
+ private static native void focus(Element el)
+ /*-{
+ try {
+ el.focus();
+ } catch (e) {
+
+ }
+ }-*/;
+
public String getTheme() {
return theme;
}