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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ascii in _KeyPress(KeyAscii As Integer) function

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hi all. The event in VB6 for form objects called

objectName_KeyPress(KeyAscii As Integer)

reads a key press and has the ascii value as a parameter.

If you put a pause point in the function with a reference to the parameter and press keys in the field, you can find out the ascii value of whatever you want by mouse over of the variable. My question is....
Why will 'tab' not register as a key press. The function never launches when 'tab' is pressed? I know that 'tab' is ascii 9 but the keyPress event ignores it. Is there a way to have it recognized? Thanks all
PB
 
The Tab key can be detected in the object's Keydown event.

Robert
 

It Can?
Yes, but only if all controls do not have the TabStop property set to True?
 
CCLINT: I've never had to trap it, so I didn't know that the tabstop would cause a problem. I see your point though. Would GetAsyncKeyState be a way around this?

Robert
 
Yes.
You shouldn't ever need a reason to trap it, as it has a predefined purpose as a Windows standard.

There is a way, if you have at least one control on the form which has a validate event. The tab key forces focus to the next control in line. So, the Validate and LostFocus events of the currently active control will naturally fire when this happens(well, most of the time). So, we can catch it there, as you have already identified (if you want to capture it for the form as well, you will need to do it in a timer):

Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Private Sub Text1_Validate(Cancel As Boolean)
If GetAsyncKeyState(vbKeyTab) > 0 Then
Cancel = True
'Do What you want with it here. (You do not need to Cancel if the tab key has a dual function)
End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top