-
FEATURED COMPONENTS
First time here? Check out the FAQ!
we could receive keypress:"enter" by onOK event;
and receive keypress:"ctrl+end" by setting ctrlkey="^#end".
but in somecases, we would like the message to be posted to server by press ctrl+enter,like some forums did.
Could anyone please tell me how to do this ?
Hello,
your question can be solved by the following simple example,
<textbox > <attribute name="onOK"> if (event.ctrlKey) alert("You press crtl+enter"); else alert("You press enter"); </attribute> </textbox >
Please try it!
By the way,
in developer's guide there is no straight way to listen the key event about what you said.
Thanks!
Thanks very much,hideokidd!
we could receive lots of key event by ctrlkey attribution.
if you'd like,please refere to this artical to see more details.
Another question comes out:
How to receive this in java ?
<textbox use="mytextbox">
in mytextbox.java:
------------------
public Class extends Textbox{
public void onOK(InputEvent evt){
//here: evt.ctrlKey is invalid.
//here: evt.onCtrlKey is invalid too.
//what could I do to know whether the user pressed Ctrl+Enter ?
}
}
Hello,
Here is a simple example you can try,
in zul file :
<textbox id="tb" use="mytextbox" forward="onOk=tb.onOK()"/>
in mytextbox.java :
import org.zkoss.zul.Textbox; import org.zkoss.zk.ui.event.*; public class mytextbox extends Textbox{ public void onOK(KeyEvent evt) { if (evt.isCtrlKey()) { // when pressing ctrl+enter } else { // when pressing enter } } }
Thanks!
Asked: 2008-12-22 05:23:20 +0800
Seen: 369 times
Last updated: Dec 30 '08