Visual Basic lets you test the state of the Shift, Alt and Ctrl keys only within the KeyUp, KeyDown and all the mouse-related event procedures. If you want to test the state of these keys from within another routine, you can resort to the following functions:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As _ Integer' The state of the Ctrl keyFunction CtrlKey() As Boolean CtrlKey = (GetAsyncKeyState(vbKeyControl) And &H8000)End Function' The state of either Shift keysFunction ShiftKey() As Boolean ShiftKey = (GetAsyncKeyState(vbKeyShift) And &H8000)End Function' The state of the Alt keyFunction AltKey() As Boolean AltKey = (GetAsyncKeyState(vbKeyMenu) And &H8000)End Function