Keystroke Events

Event Name

Components

Description

onOK

window

Event: org.zkoss.zk.ui.event.KeyEvent

Denotes user has pressed the ENTER key.

onCancel

window

Event: org.zkoss.zk.ui.event.KeyEvent

Denotes user has pressed the ESC key.

onCtrlKey

window

Event: org.zkoss.zk.ui.event.KeyEvent

Denotes user has pressed a special key, such as PgUp, Home and a key combined with the Ctrl or Alt key. Refer to the ctrlKeys Property section below for 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 the submit, cancel and shortcut functions.

As illustrated below, doA() is invoked if user pressed ENTER when T1 got the focus, and doB() is invoked if user pressed ENTER when T2 got the focus.

<window id="A" onOK="doA()">
    <window id="B" onOK="doB()">    
        <textbox id="T1"/>        
    </window>    
    <textbox id="T2"/>    
</window

Notice that a window doesn't receive the keystroke events that are sent for the inner window, unless you post them manually. In the above example, the event won't be sent to window A, if T1 got the focus, 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 by the ctrlKeys property. In other words, only key strokes specified in the ctrlKeys property is sent back to the server. For example, the onCtrlKey event is sent if a user clicks Alt+C, Ctrl+A, F10, or Ctrl+F3.

<window ctrlKeys="@c^a#10^#3">
...

The following is the syntax of th ctrlKeys property.

Key

Description

  

^k

A control key, i.e., Ctrl+k, where k could be a~z, 0~9, #n and ~n.

  

@k

A alt key, i.e., Alt+k, where k could be a~z, 0~9, #n and ~n.

  

$k

A shift key, i.e., Shift+k, where 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.