1

How to receive a "ctrl+enter" keyevent ?

asked 2008-12-22 05:23:20 +0800

evpole gravatar image evpole
481 2

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 ?

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2008-12-22 08:03:18 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2008-12-22 10:06:32 +0800

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!

link publish delete flag offensive edit

answered 2008-12-22 09:23:44 +0800

evpole gravatar image evpole
481 2

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.

link publish delete flag offensive edit

answered 2008-12-29 09:44:22 +0800

evpole gravatar image evpole
481 2

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 ?
}

}

link publish delete flag offensive edit

answered 2008-12-29 11:10:51 +0800

hideokidd gravatar image hideokidd
750 1 2

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
	}	
}
}

You can revise it to achieve your goal.
Hope this can help a lot.

Thanks!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-12-22 05:23:20 +0800

Seen: 369 times

Last updated: Dec 30 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More