I have used the SendMessage Function to send text to another program's text box. The program requires that the enter key be hit to send the text.
Anyone know how I can make my program use the enter key?:confused:
Printable View
I have used the SendMessage Function to send text to another program's text box. The program requires that the enter key be hit to send the text.
Anyone know how I can make my program use the enter key?:confused:
Use the API SendMessageLong and pass vbKeyReturn as one of the parameters. If you need some source, just ask.
I have not tested this, but this may help you get where you want to be:
1. determine the ascii value of the enter key, it should be 13, but I don't remember if this is hex or base 10. To find the ascii value of any key, use KeyPress, like so:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Print KeyAscii
End Sub
Now, run program and press the enter key
2. Convert this number to a character and use Send Message to send this also, like:
dim KeyAscii as Integer (or could be Long)
dim Acharacter as String
Acharacter = Chr(KeyAscii)
Append Acharacter to the string you wish to send using "&".
Oafo, some code example would help out a lot, thanks.
stevereno, I tried your method but I don't know what constant to use. With WM_SetText, I see a square box.
Here's what I used:
acharacter = Chr(13)
Mess = txtWindow.Text & acharacter
Sendit = SendMessage(qWnd, WM_SETTEXT, ByVal 0&, ByVal Mess)
Is WM_SETTEXT wrong ?
I do not know enough to tell you what value to use as the second parameter. I think you may need to play with a few things unless you can get more experienced help, but here is something you might look into:
go to http://www.allapi.net/apilist/apilist.php?beginletter=S
click on SendMessage
review the examples and see how they have used a variety of things for that second parameter...
Send Message:
Const LB_FINDSTRING = &H18F
Redirect output:
Private Const EM_SETSEL = &HB1
Private Const EM_REPLACESEL = &HC2
Hotkey:
Const WM_SETHOTKEY = &H32
Const WM_SHOWWINDOW = &H18
Rich Text Line Numbers:
Private Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Drag Form:
Const WM_NCLBUTTONDOWN = &HA1
It almost seems that this number is a function of the app you are sending the string into.
all for now
THANKS A LOT FOR YOUR HELP!
I used: keybd_event(VK_RETURN, 1, 0, 0)
and got it to work. I really appreciate your help.
The only problem with keybd_event is it requires focus. If you can not insure it will have focus, you should try this:
I took the code from my c++ program, but I do not see why it wouldn't work in vb. The advantage is that it does not require that the form have focus. Hope this helps.Code:
PostMessage (arrays[1], WM_KEYDOWN, 13, 0) ;
PostMessage (arrays[1], WM_KEYUP, 13, 0) ;
Joe
Here is the VB equivilent of Joey's code.
Code:PostMessage hwnd_of_window, WM_KEYDOWN, vbKeyReturn, 0
Wow, you guys are really helpful!
Thanks for code Joey and Megatron.