Common Desktop Environment: Desktop KornShell User's Guide

Event Handler Context Variables

An application registers event handlers with a widget to specify an action to occur when one of the specified events occurs. The action can be any arbitrary dtksh command line. For example:

XtAddEventHandler $W "Button2MotionMask" false "ActivateProc" 
XtAddEventHandler $W "ButtonPressMask|ButtonReleaseMask" \
       false "echo action"

Two environment variables are defined to provide context to the event handler:

EH_WIDGET

Set to the ID of the widget for which the event handler is registered.

EH_EVENT

Set to the address of the XEvent which triggered the event handler.

Access to the fields within the XEvent structure is shown in the following example:

if [ ${EH_EVENT.TYPE} = "ButtonPress" ]; then
        echo "X = "${EH_EVENT.XBUTTON.X}
        echo "Y= "${EH_EVENT.XBUTTON.Y}
     elif [ ${EH_EVENT.TYPE} = "KeyPress" ]; then     
			  echo "X = "${EH_EVENT.XKEY.X}
        echo "Y = "${EH_EVENT.XKEY.Y}    
fi