[RESOLVED] How do I implement use of Key + Click?
Hey guys! In my program a user clicks on this command button to access the next form. However, I want to implement it such a way that when a user holds down the ctrl key AND clicks on the command button, it will bring them to another "secret" form. How do I do this? Thanks for the help!
Re: How do I implement use of Key + Click?
(If you don't want to use API) Use the MouseUp event instead of Click event.
vb Code:
Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim CtrlDown As Integer
CtrlDown = Shift And 7
If CtrlDown = vbCtrlMask Then 'control key pressed
MsgBox "Show HIDDEN form"
Else
MsgBox "Show regular form"
End If
End Sub
Reference:
http://msdn2.microsoft.com/en-us/lib...30(VS.60).aspx
http://msdn2.microsoft.com/en-us/lib...14(VS.60).aspx
Re: How do I implement use of Key + Click?
What does this part mean?
Re: How do I implement use of Key + Click?
Anyone can teach me about this?
Re: How do I implement use of Key + Click?
Quote:
Originally Posted by zabimaru
What does this part mean?
Read this:
http://msdn2.microsoft.com/en-us/lib...234(VS.60).asp
Re: How do I implement use of Key + Click?
And here is used as a bitwise comparison operator. (See bottom part of this page.)
These pages may give you more information:
http://www.bitwisemag.com/2/Bit-Shif...Visual-Basic-6
http://groups.google.com/group/comp....ab2629525741bf
(IMO, the best place to learn about bitwise operation is from the related chapter in a C/C++ book or from the logic-gates chapter from your college digital electronics book and a little bit of binary mathematics.)
Re: How do I implement use of Key + Click?
Actually
Code:
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Shift And 7 = vbCtrlMask Then 'only look at the Shift, Control and Alt keys
'vbShift Mask and vbAlt Mask also work
'and the bits can be ORed
'control key alone was pressed
MsgBox "Show HIDDEN form"
Else
'control key alone wasn't pressed
MsgBox "Show regular form"
End If
End Sub
will also work.
Re: How do I implement use of Key + Click?
Herm.. So if instead I want a hidden form to pop up, upon pressing and holding down Ctrl + Shift + A, does the following code work?
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyCtrl And KeyCode = vbKeyShift And KeyCode = vbKeyA Then
frmHidden.Show
End If
End Sub
And set KeyPreview to True?
Re: How do I implement use of Key + Click?
Try
vb Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If (Shift And vbCtrlMask) = vbCtrlMask And KeyCode = vbKeyA Then
frmHidden.Show
End If
End Sub
Re: How do I implement use of Key + Click?
Your code worked Hack, mine broke haha. Thanks a lot for the help! =)
Re: [RESOLVED] How do I implement use of Key + Click?
That'll work if they hold down Ctrl + A or Shift + Ctrl + A. You want
Code:
If (Shift And (vbCtrlMask Or vbShiftMask) ) = (vbCtrlMask Or vbShiftMask)
And KeyCode = vbKeyA Then