LastInputAction Method
The LastInputAction method populates the InputEvent attributes with the values corresponding to the most recent input action of the specified type.
This method has the following syntax:
integer = InputEvent.LastInputAction(action = varchar(32)[, frame = FrameExec]
[, targetfield = FormField])
This method has the following parameters:
action
Specifies the name of the action to be recorded. Allowed values are:
'mousedown'
'mouseup'
'mousemove'
'mousehover'
'mousedrag'*
'mousedrag_down'*
'mousedrag_up'
Note: *'mousedrag' and 'mousedrag_down' are equivalent.
frame
Specifies the frame in which the action took place.
Default: the calling frame
targetfield
Specifies the field the action was applied to.
Default: the field associated with the last input action of the specified type. This may be null if no field was involved.
The method returns ER_OK if the specified action was recorded, ER_KEYNOTFOUND if the action was unrecorded, or ER_FAIL if the call failed.
Example—LastInputAction method:
The following code obtains the coordinates of the user's last mouse-down action in the current frame (CurInputEvent is a variable of type InputEvent), and the field the mouse-down was applied to. In this example, the coordinates are converted from pixels to absolute units:
pixeldensity = float4(cursession.PixelScreenWidth) / float4(cursession.ScreenWidth);
CurInputEvent.LastInputEvent(action='mousedown');
x = float4(CurInputEvent.x) / pixeldensity;
y = float4(CurInputEvent.y) / pixeldensity;
frame = curframe;
if curframe.InstanceIdentifier != CurInputEvent.FrameID then
frame = CallingFrame();
endif;
framename = frame.ObjectSource.Name;
fields = CurInputEvent.Frame.TopForm.FieldByProperties(attributename='instanceidentifier', value=CurInputEvent.FieldID);
if fields.LastRow > 0 then
clickedfield = fields[1];
fieldname = clickedfield.FullName;
endif;
framename = CurInputEvent.Frame.ObjectSource.Name;
string.Value = 'Last mouse down:: in frame ":framename", on field ":fieldname", at location xleft=:x, ytop=:y';
message string.ExpandParm().Value;
The following code gets a copy of the sprite touched by the last mouse move at the size, opacity, and orientation that it appears on the display, together with the sprite's x,y location on the field:
CurInputEvent.LastInputEvent(action='mousemove');
/* … get frame, framename, hostfield, and fieldname as above … */
if CurInputEvent.Sprite.SpriteIndex > 0 then
CurInputEvent.Sprite.SpriteImage(
displayfield=hostfield, sprite=Byref(touchedsprite), x=Byref(x), y=Byref(y));
string.Value = 'Sprite touched by last mouse move:: in frame ":framename", ' +
+ 'on field ":fieldname", '
+ 'at location xleft=:x, ytop=:y, '
+ 'with width=:touchedsprite.WidthPixels '
+ 'and height=:touchedsprite.HeightPixels ';
message string.ExpandParm().Value;
else
message 'No sprite was touched';
endif;