Skip to content

AddKeyHandler - cBaseLocalControlHost

Adds a client side key handler

Type: Procedure

Parameters

Parameter Type Description
hMsg Handle The message handle of a published procedure that will be called when the key event occurs
iKeyCode Integer JavaScript key code to handle
bShift Boolean Determines whether Shift key needs to be pressed to trigger event
bAlt Boolean Determines whether Alt key needs to be pressed to trigger event
bCtrl Boolean Determines whether Crtrl key needs to be pressed to trigger event

Syntax

Procedure AddKeyHandler Handle hMsg Integer iKeyCode Boolean bShift Boolean bAlt Boolean bCtrl

Call Example

Send AddKeyHandler hMsg iKeyCode bShift bAlt bCtrl

Description

It is possible to assign custom key handlers to controls and containers. This is done by using the AddKeyHandler and RemoveKeyHandler procedures. These procedures are client actions and the administration of key handlers is kept on the client. This means that these procedures should be used after the control is available on the client or when it is loaded to the client. Common practice will be to call these procedures during the OnLoad event.

The system relies on the HTML DOM Event bubbling system, so key events inside controls can be handled on their wrapping containers. So, a key handler on the view will catch key events on a form inside that view. If a key event is handled by a control or container, it will stop bubbling and other handlers will not be triggered. This is also true for key handlers implemented in the client-side control. The default browser behavior will be cancelled, if possible.

JavaScript key codes need to be used to define which key we are handling. See http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes to learn these.

Procedure InfoKey Integer iKeyCode Boolean bShift Boolean bAlt Boolean bCtrl
    Send ShowInfoBox "This is an information dialog!"
End_Procedure

WebPublishProcedure InfoKey

Procedure OnLoad
    Send AddKeyHandler (RefProc(InfoKey)) 112 False False False
End_Procedure

The example above shows how to attach a procedure to the F1 key immediately when the application is loaded.