MouseEvent.KeyButtonState Property
Visio Automation Reference |
Returns the state of mouse buttons and the SHIFT and CTRL keys associated with a mouse event. Read-only.
Version Information
Version Added: Visio 2003
Syntax
expression.KeyButtonState
expression A variable that represents a MouseEvent object.
Return Value
Long
Remarks
Possible values for KeyButtonState can be a combination of any of the values shown in the following table, which are declared in VisKeyButtonFlags in the Visio type library. For example, if KeyButtonState returns 9, it indicates that the user clicked the left mouse button while pressing CTRL.
Constant | Value |
---|---|
visKeyControl |
8 |
visKeyShift |
4 |
visMouseLeft |
1 |
visMouseMiddle |
16 |
visMouseRight |
2 |
Example
This class module shows how to define a sink class called MouseListener that listens for events fired by mouse actions in the active window. It declares the object variable vsoWindow by using the WithEvents keyword. The class module also contains an event handler for the MouseDown event that prints to the Immediate window the state of the mouse buttons and CTRL and SHIFT keys when the event fired.
To run this example, insert a new class module in your VBA project, name it MouseListener, and insert the following code in the module.
Visual Basic for Applications |
---|
|
Then, insert the following code in the ThisDocument project.
Visual Basic for Applications |
---|
|
Save the document to initialize the class, and then click anywhere in the active window (optionally, while pressing SHIFT and/or CTRL) to fire a MouseDown event. In the Immediate window, the handler prints the name of the mouse button that was clicked to fire the event. If you pressed either or both of the keys, the name of the key or keys you pressed will print as well.
See Also