devxlogo

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

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Five Early Architecture Decisions That Quietly Get Expensive

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.