PDA

Click to See Complete Forum and Search --> : VB not detecting key press...


Gimpster
Dec 30th, 1999, 04:16 AM
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).]

thinh
Dec 30th, 1999, 04:31 AM
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

Gimpster
Dec 30th, 1999, 04:39 AM
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

Dec 30th, 1999, 04:44 AM
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
kvision@gate.net

Gimpster
Dec 30th, 1999, 04:48 AM
Ok, here is my 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

LG
Dec 30th, 1999, 04:50 AM
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.

Gimpster
Dec 30th, 1999, 04:52 AM
So, if I can't use KeyAscii to check if they pressed the Delete key, then what would I use?

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

LG
Dec 30th, 1999, 04:54 AM
As I told before: Key_Down ar Key_Up events

Gimpster
Dec 30th, 1999, 05:00 AM
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

LG
Dec 30th, 1999, 05:05 AM
You are confused!

everithing is the same:

if KeyCode = vbKeyDelete

Dec 30th, 1999, 05:07 AM
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
kvision@gate.net

Gimpster
Dec 30th, 1999, 05:12 AM
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

LG
Dec 30th, 1999, 05:15 AM
Any time Ryan, any time

Dec 30th, 1999, 05:16 AM
Dohh!

Damn, and I tried .. LOL

Still testing my Sig.. LOL!


------------------
John T. Mieske
Knight Vision Enterprises
kvision@gate.net