Previous Document Next Document

Making macros user-friendly : Providing user interaction for macros : Capturing mouse clicks


Capturing mouse clicks

To get the position of a single mouse click, you can use the GetUserClick method of the Document class. This method pauses the macro until the specified period of time elapses, or until the user clicks in the document or presses Escape. Here is a VBA example that uses the Document.GetUserClick method:

Dim doc As Document, retval As Long
Dim x As Double, y As Double, shift As Long
Set doc = ActiveDocument
doc.Unit = cdrCentimeter
retval = doc.GetUserClick(x, y, shift, 10, True, cdrCursorPick)

The following parameters for the Document.GetUserClick method are coded into the preceding example:

 
The variable x returns the horizontal position of the mouse click.
 
The variable y returns the vertical position of the mouse click.
 
The parameter shift returns the combination of the Shift, Ctrl, and Alt keys that is held down by the user when clicking the mouse. The Shift, Ctrl, and Alt keys are assigned values of 1, 2, and 4 (respectively), the sum of which is the returned value.
 
The value 10 specifies the number of seconds for the user to click in the document.
 
The value True specifies that the SnapToObjects parameter is enabled.
 
The value cdrCursorPick specifies that the icon for the Pick tool is used for the cursor icon. (You cannot use a custom icon.)

One of the following values is returned:

 
0 — The user successfully completes the click.
 
1 — The user cancels by pressing Escape.
 
2 — The operation times out.

 
The returned coordinates are relative to the origin of the page and, unless explicity specified, are in document units.

To get the shapes under the returned click point, you can use the method SelectShapesAtPoint (which is a member of Page), as in the following VBA example:

doc.ActivePage.SelectShapesAtPoint x, y, True

A value of True selects unfilled objects, while False does not select unfilled objects.

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.