KeyState Object

See also:  Classes, Controls

The KeyState object is a global object which can be used to determine the state of various virtual keys.

Properties:

Control
Shift
Menu
LeftControl
LeftShift
LeftMenu
RightControl
RightShift
RightMenu

The LeftControl, LeftShift, and LeftMenu properties return boolean values indicating the state of the Control, Shift, and Menu buttons on the left-hand side of the keyboard (true = button is down, false = button is up).

The RightControl, RightShift, and RightMenu properties return the state of the corresponding buttons on the right-hand side of the keyboard.

The Control, Shift, and Menu properties can be used to indicate whether either button is down without distinguishing between left and right.

All of these properties are Read Only, and are available only at run-time.

Example:

Public Sub Form_Mouse_Down()
    If Button = vbRightButton Then
        'Show a popup menu in response to right-clicking on the form,
        'but only show the secret menu item if the shift key is down.

        mnumPopupSecretItem.Visible = KeyState.Shift
        PopupMenu mnumPopup
    End If
End Sub

 

Home

Copyright and Disclaimer