Results 1 to 8 of 8

Thread: How do you use KeyPress event to capture "Enter" key?

  1. #1

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290

    Post

    that's it!

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Try this:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
            'do whatever you want 
        End If
    End Sub
    ------------------
    Visual Basic Programmer (at least I want to be one)
    ------------------
    PolComSoft
    You will hear a lot about it.



    [This message has been edited by QWERTY (edited 11-08-1999).]

  3. #3

    Thread Starter
    Hyperactive Member billwagnon's Avatar
    Join Date
    Jul 1999
    Location
    St. Louis, Missouri, Mississippi Valley
    Posts
    290

    Post

    thanks!


  4. #4

    Smile

    The ENTER key is never detected on my system through AScii vbKey Return. I have even tried toggling the keyPreview option of the form.

    I have also tried the following code but the ENTER key does not return anything. Others work well.

    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyF1: MsgBox "F1 is your friend."
    Case vbKeyDelete: MsgBox "F2 could copy text."
    Case vbKeyReturn: MsgBox "F3 could paste text."
    Case vbKeyF4: MsgBox "F4 could format text."
    End Select

    End Sub

    Please reply on my email address.
    Web Developer

  5. #5
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Simple.
    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2.  If KeyAscii = 13 Then
    3.   MsgBox "Enter was pressed!"
    4.  End If
    5. End Sub
    Does this help?
    Luke

  6. #6

    ENTER Key Problem

    Dear Members thanks a lot for such quick response.I am thrilled. Mr Ram's observation regarding change in focus is perhaps what I am experiencing.
    Mr mcai has suggested putting the code in the Text sub. It works there.

    I am making a Windows like calculator where bith mouse and keyboard inputs are acceptable even if the user enters half the math expression with mouse and then decides to use keyboard .

    Is there any method where I can put the detailed ( e.g Equals formula for +,-,/,sqr) code in the button's click sub routine and then call this routine in the button's KeyPress routine, thus reducing file size.
    Web Developer

  7. #7
    Frenzied Member macai's Avatar
    Join Date
    Jul 2001
    Location
    Napanoch NY
    Posts
    1,228
    Excuse me, but are you saying that your program is an advanced
    calculation program? A program that you can enter "5^2+(2^3)"
    and it will return 33 ? If that it what you mean, this program
    sounds very useful.
    Luke

  8. #8

    ENTER Key Problem

    Well I don't say that my simple Math calculator is an advanced program at the moment. But it needs to mimic the Windows calculator which does not mind which part of an expression is comming from mouse click and which by keyboard. At the same time I need to keep the program size small i.e by avoiding repeating the code for click and keypress events.
    hope I am able to convey my message.

    I am really impressed by your quick responses. My friend is with me and finding it unbelievable.
    Web Developer

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