|
-
Feb 27th, 2001, 03:27 PM
#1
Thread Starter
Lively Member
Does anyone know how to detect the last key that was pressed in a LostFocus() event for a button. The button is at the bottom of my form, and I would like for the fist field to receive focus if they pressed the tab key. I read this in a post, but they didn't give the code.
Thanks.
-
Feb 27th, 2001, 04:07 PM
#2
PowerPoster
Why do you need to detect the last key pressed? If you set the Tabindex of the first control to 0, and the last control has the last index, then it will go back to 0.
-
Feb 27th, 2001, 04:28 PM
#3
Thread Starter
Lively Member
I can't
The form actually has tabs on it. So the two controls are on the same tab. Since there is only one tab order, I can not do that.
Thanks for the suggestion though.
Does anyone know how to do this?
-
Feb 27th, 2001, 05:35 PM
#4
Thread Starter
Lively Member
Please Help!
This is all I have left to complete my project. Is there another approach that I am not thinking of? I just need to capture when tab is hit from a button.
Thanks.
-
Feb 27th, 2001, 06:46 PM
#5
PowerPoster
That's not what I meant. Each control, no matter if you have tabs on your program or not, have a tab index. But, if you want to do it your way, here is some code.
Code:
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then
Text1.SetFocus
End If
End Sub
I don't know if that will work for sure... try it and see
-
Feb 27th, 2001, 06:49 PM
#6
PowerPoster
oh wait. I see now that you are trying to use command buttons. here is some updated code.
Code:
Private Sub Command2_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Then Command1.SetFocus
End Sub
and set the tabstop values or all the controls to false. That should work.
-
Feb 27th, 2001, 10:20 PM
#7
Thread Starter
Lively Member
Thanks for the help
Thanks for your replies. I was not clear enough in my second post. The reason I could not use the tab stops is that each tab, on the form has this same situation. So I could use it for one instance, but not all three.
The users of my app want the focus to return to the first field on the tab when they tab past the last button on the tab. They want this on all three tabs, so I can not set the tab stop to the same number on three controls.
Anyway, I will try this tomorrow when I get to work.
Thanks again for your help.
-
Feb 28th, 2001, 09:03 AM
#8
Thread Starter
Lively Member
KeyPress
The KeyPress event does not seem to fire on a command button, when you hit the tab key. Key up and key down do not either. Does anyone have any ideas?
-
Feb 28th, 2001, 09:19 AM
#9
transcendental analytic
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Command1_LostFocus()
If GetAsyncKeyState(vbKeyTab) Then Debug.Print "tab"
If GetAsyncKeyState(vbKeyLeft) Then Debug.Print "left"
If GetAsyncKeyState(vbKeyRight) Then Debug.Print "right"
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Feb 28th, 2001, 09:33 AM
#10
Thread Starter
Lively Member
Thanks Kedeman
I just found that on the Microsoft Support Site, and I was fixing to post it. For the record, it works great.
Thanks again for all of your input.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|