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:
Set to the ID of the widget for which the event handler is registered.
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