Results 1 to 11 of 11

Thread: [RESOLVED] How do I implement use of Key + Click?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Resolved [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!

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.    Dim CtrlDown As Integer
    3.    
    4.    CtrlDown = Shift And 7
    5.    
    6.    If CtrlDown = vbCtrlMask Then 'control key pressed
    7.         MsgBox "Show HIDDEN form"
    8.    Else
    9.         MsgBox "Show regular form"
    10.    End If
    11.    
    12. 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
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: How do I implement use of Key + Click?

    vb Code:
    1. CtrlDown = Shift And 7

    What does this part mean?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: How do I implement use of Key + Click?

    Anyone can teach me about this?

  5. #5
    Lively Member
    Join Date
    Feb 2007
    Posts
    99

    Re: How do I implement use of Key + Click?

    Quote Originally Posted by zabimaru
    vb Code:
    1. CtrlDown = Shift And 7

    What does this part mean?
    Read this:

    http://msdn2.microsoft.com/en-us/lib...234(VS.60).asp
    Last edited by lewmur; Apr 18th, 2007 at 01:02 PM.

  6. #6
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.)
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    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?

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How do I implement use of Key + Click?

    Try
    vb Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. If (Shift And vbCtrlMask) = vbCtrlMask And KeyCode = vbKeyA Then
    3.    frmHidden.Show
    4. End If
    5. End Sub

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jan 2007
    Posts
    95

    Re: How do I implement use of Key + Click?

    Your code worked Hack, mine broke haha. Thanks a lot for the help! =)

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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
    Last edited by Hack; Apr 19th, 2007 at 01:25 PM.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width