Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shift+Doubleclick Event 1

Status
Not open for further replies.

MatthewGB

Programmer
Oct 22, 2002
39
AU
How would i go about setting up an event for a commandbutton or whatever, so that it is triggered if i hold Shift and Double-click the mouse?

I know that you simply use the dblclick event, but im not sure of the correct syntax for using the shift key as the argument.

Any help is appreciated.

Thanks

Matt
 
It's not fool-proof because the focus may not always be on the form, but this comes close.
Note that you would need to trap key up/down for every object on the form that can receive focus.
=====================================================
Code:
Option Explicit
Dim shifted As Boolean

Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  If shifted Then
    MsgBox "Shift-Double-Click"
  Else
    MsgBox "Double-click (no shift)"
  End If
Code:
  ' Turn off shifted flag in case user lifts shift key while
  ' focus is on message box.
Code:
  shifted = False
End Sub

Private Sub CommandButton1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 16 Then shifted = True
End Sub

Private Sub CommandButton1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 16 Then shifted = False
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 16 Then shifted = True
End Sub

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
  If KeyCode = 16 Then shifted = False
End Sub
========================================================
 
Thanks for the help Zathras. I works at treat on commandbuttons etc. I was intending to use it on a image or label, but it appears that the keyup/down events dont support labels or images. But thats no major hassle.

Anyway, thanks once again.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top