Results 1 to 14 of 14

Thread: VB not detecting key press...

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    I have some code in a text_KeyPress()Event. and when I hit the Delete key, VB does not recognize the key press. Any ideas why?

    ------------------
    Ryan


    [This message has been edited by Gimpster (edited 12-30-1999).]

  2. #2
    Lively Member
    Join Date
    Jun 1999
    Location
    Garden Grove, CA, USA
    Posts
    110

    Post

    well, if you want the key to press in the form then use the keypress() event of form to detect it. And if you want the key press should be done any where then you must use window API to call out the event and get the key...

    Unfortunatly, i don't know much about API so this is all i can do for you...

    ------------------
    ngphuocthinh

  3. #3

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    No, no, no...I've got the KeyPress()Event in the right place, but I've stepped through the code as VB executes it and VB simply does not recognize the Delete key in the KeyPress event, it doesn't even check the KeyPress event code.

    ------------------
    Ryan

  4. #4
    Guest

    Post

    Some keys use Character Code Combinations such as the Delete or Function keys. They don't use the simple straight Ascii codes that the Numeric and Alphanumeric codes use. Could that be the problem? I don't know your code, so if this is not what your talking about, please be gentle.. LOL



    ------------------
    John T. Mieske
    Knight Vision Enterprises

    [email protected]

  5. #5

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Ok, here is my code:

    Code:
    Private Sub txtViewTable_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyReturn Then
            KeyAscii = 0
            cmdViewTable.SetFocus
            cmdViewTable.Value = True
            Exit Sub
        End If
        If KeyAscii = vbKeyBack Then
            KeyAscii = 0
            If txtViewTable.SelText = txtViewTable.Text Then
                listTables.Text = ""
                TextChanged = False
                Exit Sub
            End If
            Dim x As Long
            x = Len(txtViewTable.Text) - Len(txtViewTable.SelText)
            x = x - 1
            txtViewTable.Text = Mid(txtViewTable, 1, x)
            Exit Sub
        End If
        If KeyAscii = vbKeyDelete Then
            KeyAscii = 0
            txtViewTable.Text = txtViewTable.Text - txtViewTable.SelText
            TextChanged = False
            Exit Sub
        End If
        TextChanged = True
    End Sub
    Now, my problem is that when I am running my program and I hit the Delete key, VB does not even run through this Event code. It never even gets to the If...Then Statements in here, it just skips right over the Event code.

    ------------------
    Ryan

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Because DELETE is a "spesial" key.
    Key_Press Detects only ASCII which don't include DELETE

    But you can use Key_up, Key_down events. They operate with KeyCodes wich are clightly different from ASCII, and those events will recognize DELETE key.

    Try it.

  7. #7

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    So, if I can't use KeyAscii to check if they pressed the Delete key, then what would I use?

    ------------------
    Ryan

  8. #8
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    As I told before: Key_Down ar Key_Up events

  9. #9

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Yes, I understand that it goes in the Key_Down or Key_Up event procedures, but before I had this statement:

    If KeyAscii = vbKeyDelete Then...

    But you said that ASCII doesn't include the Delete key. So my question is this: What do I put in place of the KeyAscii in this statement? Thanks for your patience.

    ------------------
    Ryan

  10. #10
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    You are confused!

    everithing is the same:

    if KeyCode = vbKeyDelete

  11. #11
    Guest

    Post

    Here you go, read this tip. It's not about the DELETE key, but might prove useful.

    http://www.vb-world.net/tips/tip71.html

    Hope this helps..



    ------------------
    John T. Mieske
    Knight Vision Enterprises

    [email protected]

  12. #12

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Thank you, LG, you answered my question without even knowing it. Because, you see, I didn't know about KeyCode. I was exclusively using KeyAscii before. But now it works GREAT!!!.

    ------------------
    Ryan

  13. #13
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308

    Post

    Any time Ryan, any time

  14. #14
    Guest

    Post

    Dohh!

    Damn, and I tried .. LOL

    Still testing my Sig.. LOL!


    ------------------
    John T. Mieske
    Knight Vision Enterprises

    [email protected]

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