I have implemented a CTRL Key listener in the ZK framework. However, I am having an issue with Firefox and Chrome.
If I press CTRL+R or CTRL+A or CTRL+S, my application event fires but in Firefox and Chrome, the default CTRL event fires also; refresh, select all, and save respectively. For example, if I press CTRL+A, my event is fired and all text on the page is selected.
Can anyone tell me if its a ZK issue or if I am doing something wrong.
Note: Events are fired for the whole page not only for the textbox.
In ZUL I used:
<window apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('com.web.viewmodel.MyViewModel')"
width="100%" height="100%" mode="embedded" ctrlKeys="^a^q^r^s^d"
onCtrlKey="@command('doFireCtrlKeyEvent',code=event.getKeyCode())">
..and in my Java ViewModel I used the following, this method will catch the event and pass it to the corresponding ViewModel
:
@Command
public void doFireCtrlKeyEvent(@ContextParam(ContextType.VIEW) Component view, @org.zkoss.bind.annotation.BindingParam("code") String ctrlKeyCode) {
int keyCode = Integer.parseInt(ctrlKeyCode);
String ctrlKey = "";
switch (keyCode) {
case 65:
ctrlKey = "CTRL+A";
break;
case 81:
ctrlKey = "CTRL+Q";
break;
case 82:
ctrlKey = "CTRL+R";
break;
case 83:
ctrlKey = "CTRL+S";
break;
case 68:
ctrlKey = "CTRL+D";
break;
}
Map map = new HashMap();
map.put("ctrlKeyCode", ctrlKey);
Tabpanel tabPanel = mainTab.getSelectedPanel();
Tab tab = mainTab.getSelectedTab();
Include inc = (Include) tabPanel.getChildren().get(0);
if (inc != null) {
if (inc.getFirstChild() instanceof Window) {
Window win = (Window) inc.getFirstChild();
Map maps = win.getAttributes();
Binder bind = (Binder) maps.get("binder");
if (bind == null)
return;
bind.postCommand("doCtrlKeyAction", map);
}
if (inc.getFirstChild() instanceof Hbox) {
Hbox hbox = (Hbox) inc.getFirstChild();
Map maps = hbox.getAttributes();
Binder bind = (Binder) maps.get("binder");
if (bind == null)
return;
bind.postCommand("doCtrlKeyAction", map);
}
}
}