Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Clarification on KEYASCII of KeyPress Event

Status
Not open for further replies.

AngO

Instructor
Jan 31, 2002
155
US
Hi All,

When I try to get the KeyAscii for the Enter Key, It works
on some form's controls but not in some other forms.
What I am trying to do is ,
If keyascii = 13 then
sendkeys"{Tab}"
End if

it works in most of the places. But in some form I couldn't.
please help me out.
Any help would be greatly appreciated


Thanks

Ango
 
Ango,

Your problem regarding keyascii is best answered when all of the controls or objects on your form is defined and coded in a keypress event. You mentioned that some forms which you try to code out could not work the same way from your other forms. You should keep in mind that when you use the keyascii codes, be sure that the event you place the codes for it is a keypress event.
Hope you get it.

d3xTeR


 
Hi d3xTeR

Thanks for you response.
I put the code in the keypress event of
the control.

Ango
 
Hi d3xTeR

I can get the KeyAscii for all the characters except for
Enter Key, I don't know what's mystery behind it.

Ango
 
Setting KeyAscii to 0 after doing the SendKeys has always worked for me, in every control I've ever use it in. Try this:

If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
 
Do you have a button with the "Default" property set to true? I think it will intercept the enter key before any of the keypress events see it.

Chip H.
 
Hi Hackster, Chiph ,d3xTeR

Thanks for your help.
After putting
keyascii = 0
it works fine.


Thanks

Ango


 
Hello Hackster

I have been reading through some KeyPress events and came across an interesting one of yours dated 31st May 2001.

You refer to some coding, namely:

If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If

I am trying to fathom out what KeyPress is exactly, and wonder if you would be good enough to explain what the 13 represents in your code.

I have some code here:

Option Explicit

Function OnlyNumericKeys(KeyAscii As Integer) As Integer

Select Case KeyAscii
Case 8, 46, 48 To 57 ' allow backspace, '.' and digits
Case Else: KeyAscii = 0 ' reject everything else
End Select
OnlyNumericKeys = KeyAscii

End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = OnlyNumericKeys(KeyAscii)
End Sub



This code works. It effectively disables the keyboard except for numeric characters. But what do the numbers 8, 46, 48 To 57 mean?

I would be grateful for any help you could offer.

Cheers.

 
Hi,
All keys have values assigned to them based on the ASCII character set.(see msdn or surf) A key press is an event that can be captured;

Private Sub Text1_KeyPress(KeyAscii As Integer)
and KeyAscii is the integer value for that key

Case 8, 46, 48 To 57
8 is the value of the Backspace key
46 = decimal
48 - 57 = 0-9
all other keyboard inputs are rejected
Case Else: KeyAscii = 0

If KeyAscii = 13 Then 'if the carriage return key press
SendKeys "{tab}" 'send message to active window
KeyAscii = 0
End If

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top