SimulateMouse

(Engine-Level Function)

Description: Sets the pointer location and then sends a button press with modifiers such as Ctrl, Shift or Alt.
Returns:  
Usage: Script Only.
Function Groups: Graphics,
Related to: SetXLoc| SetYLoc
Format: SimulateMouse(Root, mouseX, mouseY, MouseButtons, ModifierKeys)
Parameters:  
Root
Required. The window object within which the mouse should point.
mouseX
Required. Any numeric expression for the horizontal location of the mouse pointer
mouseY
Required. Any numeric expression for the vertical location of the mouse pointer.
MouseButtons

Required. Any numeric expression for the mouse button(s) to be simulated.

Bit Value Mouse Button
-- 0 no buttons
2^0 1 left down
2^1 2 right down
2^2 4 middle down
2^6 64 release any buttons, as specified above, in the same call to SimulateMouse()
2^7 128 delete key
ModifierKeys

Required. Any numeric expression for the keyboard modifier to be applied to the mouse click. See comments.

Bit Value Modifier Key
-- 0 no key
2^0 1 shift
2^1 2 control
2^2 4 Alt
2^3 8 Left
2^4 16 Right
2^5 32 Up
2^6 64 Down
Comments:

Similar to SetXLoc and SetYLoc, but all in one, plus mouse buttons and modifier keys. Used primarily for testing.

Only a single modifier can be specified in any call.

The key is not released automatically, but rather is release when called again with bit 15 (0x8000) set. For example, SimulateMouse(x, x, 1) sets shift and SimulateMouse(x, x, 0x8001) releases shift.

Examples:

...
mouseX = 100;
mouseY = 150;
DblClick(mouseX, mouseY);
...
<
{======================== DblClick ============================}
{ Simulates a double click of the left mouse button            }
{==============================================================}
DblClick
(
mouseX              { Left Mouse Coord                       };
mouseY              { Top Mouse Coord                        };
)
[
  Done = FALSE;
  Phase = 0;
  Constant #Btn    = 0x01; { Left click           }
  Constant #Btn_Up = 0x40; { release button       }
  Constant #Key    = 0x00; { No keyboard modifier }
]
First [
  If Timeout(!Done, 0.1);
  [
    Case(Phase,
      { Case 0 } Execute(
        { Does first mouse click }
        SimulateMouse(Root, mouseX, mouseY, #Btn, #No_Keys);
        SimulateMouse(Root, mouseX, mouseY, #Btn + #Btn_Up, #No_Keys);
      ),
      { Case 1 } Execute(
        { does second mouse click }
        SimulateMouse(Root, mouseX, mouseY, #Btn, #No_Keys);
        SimulateMouse(Root, mouseX, mouseY, #Btn + #Btn_Up, #No_Keys);
      ),
      { Case 2 }
        Result = TRUE;
    );
    Phase++;
  ]
]
>