Problem: How To Use OnPenDown/OnPenUp Scripts to Detect Pen Taps on Controls
Solution: This article describes a technique using a global PenTapInControl script in conjunction with OnPenDown/OnPenUp form scripts to detect when controls are tapped on, for use on controls that do not have an OnClick method (such as edit controls, text labels, lookups, bitmaps, etc).
Let's assume that you want to detect pen taps in a control in a manner consistent with the standard controls that support OnClick events; that is, a valid "click" is when the user taps the pen down on the control, and then lifts the pen up while still on the control. Tapping down on a control, then sliding off the control and lifting the pen when not on the control does not count as a valid click.
This can be accomplished using a combination of global functions, global variables, and OnPenDown/OnPenUp scripts on a given form.
First the global vars that we need in order to track pen tap coordinates across multiple scripts:
'pen tracking global vars
Dim gOPDX, gOPDY, gOPUX, gOPUY
[For those curious about the variable naming convention, they are named after Global OnPenDown X, Global OnPenDown Y, Global OnPenUp X, Global OnPenUp Y.]
Next the OnPenDown script on a form:
'record the pen down but don't track it around the form
'save x/y coords to global vars for use in other scripts
'note these save to the "D" or "Down" global vars
GetPenStatus(gOPDX, gOPDY)
Next the OnPenUp script. This example tracks taps for two controls, Edit1
and Edit2.
'record the pen up position but don't track it around the form
'save x/y coords to global vars for use in other scripts
'note these save to the "U" or "Up" global vars
GetPenStatus(gOPUX, gOPUY)
Dim cX, cY, cW, cH
'test if pen tapped within bounds of Edit1 control
Edit1.GetPosition(cX, cY, cW, cH)
If PenTapInControl(cX, cY, cW, cH) then
msgbox("You tapped inside Edit1")
Exit 'leave the script
Endif
'test if pen tapped within bounds of Edit2 control
Edit2.GetPosition(cX, cY, cW, cH)
If PenTapInControl(cX, cY, cW, cH) then
msgbox("You tapped inside Edit2")
Exit 'leave the script
Endif
Okay, so you can see that the OnPenUp event script calls a global function named PenTapInControl, passing it the coordinates of the control that you want to test the pen taps for. Remember that we consider it a tap ONLY if the pen taps down on the form and also lifts up from the form within the bounds of a given control. A user can tap down then slide away and lift off outside of a control and that is not considered a tap (just like the standard UI behaviour for controls). That PenTapInControl global function looks like this:
'check supplied coordinates against stored global PenUp and PenDown coords
'return True if pen tapped (down and up) in control or False if not
Function PenTapInControl( cX, cY, cW, cH )
Dim dDX, dDY, dUX, dUY
dDX = gOPDX - cX 'pen down x coordinate differential
dUX = gOPUX - cX 'pen up x coordinate differential
dDY = gOPDY - cY 'pen down y coordinate differential
dUY = gOPUY - cY 'pen up y coordinate differential
'verify that pen differentials lie within width and height of control
If ( (dDX <= cW) and (dDX >= 0) and _
(dUX <= cW) and (dUX >= 0) and _
(dDY <= cH) and (dDY >= 0) and _
(dUY <= cH) and (dUY >= 0) ) then
PenTapInControl = True
else
PenTapInControl = False
Endif
End Function
That should do it. You can then expand it to other controls by adding additional PenTapInControl tests in the OnPenUp script.
Keywords: PenTapInControl, OnPenDown, OnPenUp, pen, tap, click, global, GetPosition, GetPenStatus
KB ID: 10059
Updated: 2007-06-22
Satellite Forms KnowledgeBase Online