Public Sub Main()
SendKeys Chr(vbKeyReturn)
End Sub
Printable View
Public Sub Main()
SendKeys Chr(vbKeyReturn)
End Sub
Try the following code.
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Sub Form_KeyPress(KeyAscii As Integer)
Debug.Print KeyAscii
End Sub
Private Sub Form_Load()
keybd_event vbKeyReturn, 0, 0, 0
keybd_event vbKeyReturn, 0, KEYEVENTF_KEYUP, 0
End Sub
Maybe I missed something.
Is there a problem with mine?
No Problem !! Your code is exactly perfect:)
I used to use SendKeys but on occasions i came to know that it is slow...therefore I personally prefer Keybd_Event....Nothing ELSE...
thanks for the quick response.....
it works perfect.
steve
OK, cool. I'll keep that in mind.
Oops!! I forgot.....
Keybd_Event is capable of simulating key downs of keys..(I am not sure but I think SendKeys cannot send extended keys(Alt,Ctrl )through their virtual key codes, correct me if i am wrong) and it can also send extra information about the keys....therefore it is more than a function which just simulates the key presses....
Yes, it can simulate a key being held down, whereas SendKeys cannot.
However, he only asked for a return press.
Your example appeared somewhat like taking a BFG in to kill one drone (pardon the comparison).
However, it still gets the job done, which is the most important part.
I used SendKey in a prog I wrote in W2KPro and it flew. I ran the program in my Win95 partition and it ran like treacle.
I may try the keybd_event to allow better backward OS compatibility.
Lord_Rat, please stop being simple. You know the right answer is always the most complicated one. We expect immediate improvement lest you be shunned from the island.
Thank you.
*slaps forehead
OK .. ... .. ok