Checking for key presses in an On Click event

J_Orrell

Registered User.
Local time
Today, 23:48
Joined
May 17, 2004
Messages
55
Guys this should be simple, but isn't.

I have a button on a form and I want the On Click event behind it to check whether Shift is also being pressed when the user clicks the button (or Ctrl, or Alt, in fact any damn key will do).

I can't believe that there isn't a function in VBA like the old 1980s BASIC 'inkey' function (etc) that just simply returns the code of any key being held down at the time of the scan. I shouldn't have to mess around programming other events like KeyDown and KeyUp when I don't particularly need the key-press to trigger an event per se. There must be a neater solution.

Anyone got any ideas?

Thanks in advance.
 
You can't get away from using one of those events I'm afraid.

You could have a boolean variable that's only visible to just the form object which gets turned to True on the Click event, then check against this variable + check which Shift keys is pressed and act accordingly. Remember to set the variable back to False.
 
Thanks I'll do it that way. Can't believe it's missing a basic function to scan the keyboard without having to use an event. But if it is, it is.
 
Thanks I'll do it that way. Unbelievable that it's missing a basic function to scan the keyboard without having to use an event. But if it is, it is.
 
Thanks I'll do it that way. Unbelievable that it's missing a basic function to scan the keyboard without having to use an event. But if it is, it is.
 

Users who are viewing this thread

Back
Top Bottom