Results 1 to 10 of 10

Thread: Using the Enter key in another program's Textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    5

    Question Using the Enter key in another program's Textbox

    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?

  2. #2
    Hyperactive Member
    Join Date
    Feb 2001
    Posts
    421
    Use the API SendMessageLong and pass vbKeyReturn as one of the parameters. If you need some source, just ask.
    [vbcode]
    ' comment
    Rem remark
    [/vbcode]

  3. #3
    New Member
    Join Date
    Dec 2001
    Location
    Colorado
    Posts
    12

    possible way to send "enter"

    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 "&".

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    5

    Yes Please!

    Oafo, some code example would help out a lot, thanks.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    5

    Steve...I think it might work, but

    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 ?

  6. #6
    New Member
    Join Date
    Dec 2001
    Location
    Colorado
    Posts
    12

    what to use for 2nd parameter?

    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

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    5

    Thumbs up

    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.

  8. #8
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Another alternative...

    The only problem with keybd_event is it requires focus. If you can not insure it will have focus, you should try this:

    Code:
    PostMessage (arrays[1], WM_KEYDOWN, 13, 0) ; 
    PostMessage (arrays[1], WM_KEYUP, 13, 0) ;
    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.

    Joe

  9. #9
    Megatron
    Guest
    Here is the VB equivilent of Joey's code.
    Code:
    PostMessage hwnd_of_window, WM_KEYDOWN, vbKeyReturn, 0

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    5

    Even better ;-)

    Wow, you guys are really helpful!
    Thanks for code Joey and Megatron.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width