We help IT Professionals succeed at work.

keypress

Is there a way to modify a forms behavior (at run-time) based on a key pressed at the time of the Form_Load event?

For example, can I allow a user to enable alternate features in my program if he/she is holding down the shift (or any other) key at the time the form is loaded?

Thanks
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
maybe use variables to keep the setting, then react according to the variables' value.

regards.
try this maybe?

Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal vKey As Long) As Integer
Private Const VK_SHIFT = &H10


then use this:

If (GetAsyncKeyState(VK_SHIFT)) Then
  'Key is pressed
End If

hope this helps! you mioght have to mess around with what the GetAsync... returns.

Author

Commented:
This did the trick nicely!
Thanks
glad to help! thanks for the points and especially for the A grade ;-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.