KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using command POST CLICK to simulate a Mouse click
PRODUCT: 4D | VERSION: 6.0 | PLATFORM: Mac & Win
Published On: May 5, 2000

Suppose you want to design a form that allows an object to perform its action automatically when you move the cursor over it.


Fig1: Form1

What you want to happen with Form1 is, when the cursor enters the button area, the form method will automatically execute the method that is associated with the button without clicking it. 4D has a command that simulates this action, called POST CLICK. It works as if the user actually clicked the mouse button.

POST CLICK (mouseX; mouseY{; process}{; *})

Before you start implementing the method, you must find out what the coordinates are at the left, right, top, and bottom sides of the button. This information will be used to compare with the cursor coordinate.

The following form method is one way to implement this action.

Here is a text version of this code that you can cut and paste into your own project:

If (Form event=On Load )
 SET TIMER(10)
 <>left:=70 `The X-coordinate at the left side of the button
 <>right:=154 `The X-coordinate at the right side of the button
 <>top:=61 `The Y-coordinate at the top of the button
 <>bottom:=112 `The Y-coordinate at the bottom of the button
End if

If (Form event=On Timer )
 GET MOUSE($MouseX;$MouseY;$state) `Get the X and Y coordinates
 If ((<>left<$MouseX) & (<>right>$MouseX))
  If ((<>top<$MouseY) & (<>bottom>$MouseY))
    `Simulates a Mouse click as if the user actually clicked the Mouse button
   POST CLICK($MouseX;$MouseY;Current process)
  End if
 End if
End if