Just trying to make the enter key pressed after a time delay in vb6, all the examples I find don't seem to be working, any help?
Just trying to simulate a keystroke. Focus doesn't matter.
Just trying to make the enter key pressed after a time delay in vb6, all the examples I find don't seem to be working, any help?
Just trying to simulate a keystroke. Focus doesn't matter.
What are you trying to do? How do you know it is not working?
If you are trying to trigger an event handler you could call it in code instead of sending a key press.
You may need to supply more details. But IF you are trying to send a enter key to a VB6 authored application and it is not picking it up it usually the fact you didn't set the KeyPreview property of the form to true. Without the control with the current focus soaks up the keypress you sent.
If you authored the application that receiving the enter key. I strongly recommend that you refactor the application so that the whatever code is being triggered by enter can be done through code. This usually done by having the code moved to an area accessible to both application. This is because Sendkeys is notoriously non-deterministic and can cause a lot of strangeness.
There is a keybd_event you can use from the Win32 API info here I found it to be more reliable than SendKeys.
SendKeys should always be a last resort.
The problem is really the focus. You have to set focus prior to each send.
Just about everything can be completed via Scripting, so what are you trying to do?
I made a vb6 test app. with 1 form, 1 default button, 1 timer:
Private Sub Command1_Click()
Debug.Print CStr(Now) + " Command1"
End Sub
Private Sub Timer1_Timer()
Debug.Print CStr(Now) + " Sendkeys"
SendKeys "{Enter}"
End Sub
It seemed to work when sending to itself. 11/30/2008 6:11:38 PM Sendkeys 11/30/2008 6:11:38 PM Command1 11/30/2008 6:11:43 PM Sendkeys 11/30/2008 6:11:43 PM Command1 11/30/2008 6:11:48 PM Sendkeys 11/30/2008 6:11:48 PM Command1
Did you want to send to another process?
You can try my PushKeys program which is available here. It is syntax compatible with SendKeys but uses the keybd_event API and has a sleep function built in.
There are some problems with SendKeys on Vista. See this article by Karl Peterson for details and solution.