Results 1 to 9 of 9

Thread: Keypress event

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    39
    Hello,

    Here is my problem.
    When the user is on my form and if he / she hits ctrl + enter at the same time, I want certain text from a text box to move to another text box.

    So im thinking I would do this is a form1_keypressevent??

    enter key is chr(13) but what is the ctrl key?


    Any help.

    Thanks.

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Instead of using the KeyPress event, use the KeyDown event (or KeyUp, but try down first). That way, you can check Shift to see if shift, control, or alt was pressed when the event was fired.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  3. #3
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    As Kaverin said. Shift will return 2 if ctrl was pressed.

  4. #4
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97

    you have to trap keycode

    You have to write the code either in keyDown or keyUp not in keyascii.Since keyascii cannot trap the ctrl key whereas keycode traps it.

    So the keycode for ctrl key is 17.

    When you want to trap the code of function keys and the keys like ctrl,alt etc then you have to use keycode.

    Hope iam clear

    regards
    Anil

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    39
    I understand it now anilgoje. Thanks for all of your help people.

  6. #6
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Thumbs up This will work...

    This code will capture the "Ctrl + Enter" keys and display a message box when they are pressed.
    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        If (KeyCode = vbKeyReturn) And (Shift = vbCtrlMask) Then
            MsgBox "You pressed Ctrl + Enter"
        End If
    End Sub
    [Edited by seaweed on 11-06-2000 at 02:20 PM]
    ~seaweed

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    39

    hmmm

    I have tried both ways and It is still not working.

    First way.

    Code:
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    
          if chr(13) and chr(17) then
             msgbox"working?"
          end if
                
    End Sub
    
    '// second way
    
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
        
        If (KeyCode = vbKeyReturn) And (Shift = vbCtrlMask) Then
            MsgBox "You pressed Ctrl + Enter"
        End If    
    
    End Sub
    Any ideas?


  8. #8
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    Talking um....

    I think its not working because the first way has
    Code:
    MsgBox"working"
    'and not
    MsgBox "working"
    If not then i dont know
    retired member. Thanks for everything

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2000
    Posts
    39
    No that isnt the problem. I am only putting msgbox's up there so I can see if it works before I put in the rest of my code.

    I have also tried keyup as well as keydown events.


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