devxlogo

The status of shift keys

The status of shift keys

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

See also  Is Machine Learning Automating Creativity in Graphic Design?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist