Keystroke Events

From Documentation
Revision as of 10:45, 19 January 2022 by Hawk (talk | contribs) (correct highlight (via JWB))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


Event Name
Components / Description
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.


Key
Description
^k
The control key, i.e., Ctrl+k, where k can be a~z, 0~9, #n and ~n.
@k
The alt key, i.e., Alt+k, where k can be a~z, 0~9, #n and ~n.
$k
The shift key, i.e., Shift+k, can k could be #n and ~n.
#n
A special key as follows.


#home
Home
#end
End
#ins
Insert
#del
Delete
#left
#right
#up
#down
#pgup
PgUp
#pgdn
PgDn
#fn
A function key. #f1, #f2, ... #f12 for F1, F2,... F12.


You can use the function getKeyCode() to retrieve which key was pressed in the KeyEvent.



Last Update : 2022/01/19

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.