Results 1 to 7 of 7

Thread: KeyDown wit multiple keys

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    I want to have this code in the keydown event that if ctrl and g are pressed a certain thing happens... How do I do this

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Chage Form's KeyPreview property to TRUE and put this code on Form's KeyDown event:

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If (Shift And vbCtrlMask) > 0 Then
            If KeyCode = vbKeyG Then
                'Do your things here............
            End If
        End If
    End Sub
    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  3. #3
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    Or you simply use the keyup event instead
    test this and the msgbox willshow what key's are pressed. here are the constants.
    Constant Value Description
    vbShiftMask 1 SHIFT key bit mask.
    VbCtrlMask 2 CTRL key bit mask.
    VbAltMask 4 ALT key bit mask.

    here is some code:
    Code:
    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    If Shift Then
    MsgBox Shift & " " & KeyCode
    End If
    End Sub
    ------------------
    On Error Goto Bed :0)
    [email protected]



    [This message has been edited by onerrorgoto (edited 11-18-1999).]

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    Key_up event is being triggered twice any idea what could be causing this ?

    [This message has been edited by Inhumanoid (edited 11-18-1999).]

  5. #5
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Post

    ??
    Two msgboxes??

    ------------------
    On Error Goto Bed :0)
    [email protected]


  6. #6
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    In this case it doesn't make any difference. You can use my code on Key_Up event.

    Inhumanoid, for your question (why it happens twice). Do you have my code on Key_Down event and the code on Key_Up event???

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 1999
    Posts
    309

    Post

    nope.... I make the keydown ctrl+w event call a buttons click event... I switched to the debugger, when it's done with the click event it finishes the keydown event and then does i t again.....

    I think I'll have to solve this one my self cause it's probably some bug caused by something that has nothing to do with the keyup event....

    But thanx for the code...

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