-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I want to create shortcut for save & delete using Ctrl key.But onCtrlKey is not working properly.
Can anybody tell how to implement Ctrl key functionality?
I have tried & get final solution:
<zk>
<window apply="org.zkoss.bind.BindComposer" ctrlKeys="^c^x^v" onCtrlKey="@command('doCtrlKeyEvent',e=event)"
viewModel="@id('vm') @init('com.csdcsystems.amanda.web.viewmodel.TestViewModel')">
<label value="Hello"></label>
</window>
</zk>
public class TestViewModel {
@AfterCompose
public void doAfterCompose(@ContextParam(ContextType.VIEW)Component view)
{
Selectors.wireComponents(view, this, false);
}
@Command
public void doCtrlKeyEvent(@BindingParam("e")KeyEvent event) {
char c = (char) event.getKeyCode();
switch (c) {
case 'X':
Messagebox.show("Cutting");
break;
case 'C':
Messagebox.show("Copying");
break;
case 'V':
Messagebox.show("Pasting");
break;
default:
return;
}
}
}
Hi posingh,
Can you provide the sample code which is not working properly?
There is an example on ZKDemo, maybe you can test it first.
Regards,
Monty Pan
@MontyPan:
I am using the below code:
<button ctrlKeys="^c^x^v" label="SAVE"
id="btnSave"
onClick="@command('doSomething')">
</button>
@Wire
Button btnSave;
@SuppressWarnings("unchecked")
@AfterCompose
public void doAfterCompose(@ContextParam(ContextType.VIEW)Component view)
{
Selectors.wireComponents(view, this, false);
btnSave.addEventListener(Events.ON_CTRL_KEY, new EventListener() {
public void onEvent(Event event) throws Exception {
doCtrlKeyEvent((KeyEvent)event);
}
});
}
private void doCtrlKeyEvent(KeyEvent event) {
char c = (char) event.getKeyCode();
switch (c) {
case 'X':
Messagebox.show("Cutting");
break;
case 'C':
Messagebox.show("Copying");
break;
case 'V':
Messagebox.show("Pasting");
break;
default:
return;
}
}
@Command
public void doSomething()
{
Messagebox.show("Hariom");
}
Can you tell why this is not working.
Asked: 2012-10-15 10:00:07 +0800
Seen: 64 times
Last updated: Oct 15 '12