how to bring up a hidden button using special keys?

B

Ben

Hi all,

I would like to create a hidden button on a form, but when I only want
it to appears when I press certain keys combination, such as Shift-S-A.
That is shift key with the "S" key and the "A" key. I want to have
it so that I can do occasional system maintenance.

Can you share some thoughts with me?

Thanks,

Ben
 
J

Jack Leach

I would try the KeyPress event, but I'm not 100% on how to check for multiple
keys. You can then use KeyCode to check for the currently pressed key,
though again I'm not sure if this works with multiples. If I'm imagining
this anywhere near correctly, it would resemble something along these lines:

Private Sub Form_KeyPress()
If (KeyCode = blah) And (KeyCode = Blah2) And (KeyCode = Blah3) Then
Me.HiddenButton.Visible = Not Me.HiddenButton.Visible
End If
End Sub

Do a google search on keycodes and you should find a list of the codes for
each key pretty easily.

hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
J

John Spencer MVP

You might use something like the following - which traps the control and alt
key being down when the key is pressed

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyS And Shift = acCtrlMask + acAltMask Then
KeyCode = 0
'Show button if not visible, hide button if visible
'You should check and make sure the button does not have the
'focus if you are going to hide it. Or just move the focus
'using set focus before changing the visible property of the
'button
Me.SomeButton.Visible = Not(Me.SomeButton.Visible)
End If
End Sub

You will need to set the form's Key Preview property to True (Yes) if you want
the keystroke to be trapped. I don't know of a good method to trap both the S
and A and Shift being pressed at the same time.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top