Keystroke Events"
Maya001122 (talk | contribs) m |
|||
Line 117: | Line 117: | ||
|} | |} | ||
− | You can use the function <tt>getKeyCode()</tt> to retrieve which key was pressed in the KeyEvent. | + | You can use the function <tt>getKeyCode()</tt> to retrieve which key was pressed in the KeyEvent. |
{{ ZKDevelopersGuidePageFooter}} | {{ ZKDevelopersGuidePageFooter}} |
Revision as of 03:13, 29 December 2010
This documentation is for an older version of ZK. For the latest one, please click here.
onOK | window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox
Event: KeyEvent Denotes the user has pressed the ENTER key. |
onCancel | window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox
Event: KeyEvent Denotes the user has pressed the ESC key. |
onCtrlKey | all
Event: KeyEvent Denotes the user has pressed a special key, such as PgUp, Home or a key combination eg. Ctrl or Alt + another key. Please refer to the ctrlKeys Property section below for more details. |
The keystroke events are sent to the nearest window that has registered an event listener for the specified events. It is designed to implement submit, cancel and shortcut functions.
As illustrated below, doB() is invoked if the user presses ENTER when T1 has focus, and doA() is invoked if the user pressesENTER when T2 has focus.
<window id="A" onOK="doA()">
<window id="B" onOK="doB()">
<textbox id="T1"/>
</window>
<textbox id="T2"/>
</window>
A window doesn't receive the keystroke events that are sent for the inner window unless you post them manually. In the above example, if T1 has focus the event won't be sent to window A, no matter whether the onOK handler is declared for window B or not.
The ctrlKeys Property
To receive the onCtrlKey event, you must specify what key strokes to intercept using the ctrlKeys property. In other words, only key strokes specified in the ctrlKeys property are sent back to the server. For example, the onCtrlKey event is sent if a user presses Alt+C, Ctrl+A, F10, or Ctrl+F3.
<window ctrlKeys="@c^a#f10^#f3">
The following is the syntax of the ctrlKeys property.
The control key, i.e., Ctrl+k, where k can be a~z, 0~9, #n and ~n. | |||||||||||||||||||||||||||||||
The alt key, i.e., Alt+k, where k can be a~z, 0~9, #n and ~n. | |||||||||||||||||||||||||||||||
The shift key, i.e., Shift+k, can k could be #n and ~n. | |||||||||||||||||||||||||||||||
A special key as follows.
|
You can use the function getKeyCode() to retrieve which key was pressed in the KeyEvent.