Keystroke Events"
Maya001122 (talk | contribs) m (Created page with '{{ZKDevelopersGuidePageHeader}} {| border="1" ! <center>Event Name</center> ! <center>Components / Description</center> |- | onOK | window textbox intbox longbox doublebox de…') |
m (correct highlight (via JWB)) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
| window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox | | window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox | ||
− | Event: < | + | Event: <javadoc>org.zkoss.zk.ui.event.KeyEvent</javadoc> |
− | Denotes the user has pressed the < | + | Denotes the user has pressed the <code>ENTER</code> key. |
|- | |- | ||
Line 17: | Line 17: | ||
| window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox | | window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox | ||
− | Event: < | + | Event: <javadoc>org.zkoss.zk.ui.event.KeyEvent</javadoc> |
− | Denotes the user has pressed the < | + | Denotes the user has pressed the <code>ESC</code> key. |
|- | |- | ||
Line 25: | Line 25: | ||
| all | | all | ||
− | Event: < | + | Event: <javadoc>org.zkoss.zk.ui.event.KeyEvent</javadoc> |
− | Denotes the user has pressed a special key, such as PgUp, Home or a key combination eg. < | + | Denotes the user has pressed a special key, such as PgUp, Home or a key combination eg. <code>Ctrl</code> or <code>Alt</code> + another key. Please refer to the <code>'''ctrlKeys</code> 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. | 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, < | + | As illustrated below, <code>doB()</code> is invoked if the user presses <code>ENTER</code> when <code>T1</code> has focus, and <code>doA()</code> is invoked if the user presses<code>ENTER</code> when <code>T2</code> has focus. |
<source lang="xml" > | <source lang="xml" > | ||
Line 43: | Line 43: | ||
</source> | </source> | ||
− | 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 < | + | 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 <code>T1</code> 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 === | === The ctrlKeys Property === | ||
− | To receive the < | + | To receive the <code>onCtrlKey</code> event, you must specify what key strokes to intercept using the <code>ctrlKeys</code> property. In other words, only key strokes specified in the <code>ctrlKeys</code> property are sent back to the server. For example, the onCtrlKey event is sent if a user presses <code>Alt+C</code>, <code>Ctrl+A</code>, <code>F10</code>, or <code>Ctrl+F3</code>. |
<source lang="xml" > | <source lang="xml" > | ||
Line 52: | Line 52: | ||
</source> | </source> | ||
− | The following is the syntax of the < | + | The following is the syntax of the <code>ctrlKeys</code> property. |
Line 61: | Line 61: | ||
|- | |- | ||
| <center>^k</center> | | <center>^k</center> | ||
− | | The control key, i.e., < | + | | The control key, i.e., <code>Ctrl+k</code>, where <code>k</code> can be a~z, 0~9, #n and ~n. |
|- | |- | ||
| <center>@k</center> | | <center>@k</center> | ||
− | | The alt key, i.e., < | + | | The alt key, i.e., <code>Alt+k</code>, where <code>k</code> can be a~z, 0~9, #n and ~n. |
|- | |- | ||
| <center>$k</center> | | <center>$k</center> | ||
− | | The shift key, i.e., < | + | | The shift key, i.e., <code>Shift+k</code>, can <code>k</code> could be #n and ~n. |
|- | |- | ||
Line 117: | Line 117: | ||
|} | |} | ||
− | You can use the function < | + | You can use the function <code>getKeyCode()</code> to retrieve which key was pressed in the KeyEvent. |
{{ ZKDevelopersGuidePageFooter}} | {{ ZKDevelopersGuidePageFooter}} |
Latest revision as of 10:45, 19 January 2022
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 |
onCancel | window textbox intbox longbox doublebox decimalbox datebox timebox combobox bandbox
Event: KeyEvent Denotes the user has pressed the |
onCtrlKey | all
Event: KeyEvent Denotes the user has pressed a special key, such as PgUp, Home or a key combination eg. |
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.