Results 1 to 8 of 8

Thread: Sendmessage api question?

  1. #1

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172

    Sendmessage api question?

    using the api
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)

    what do the wParam and lParam do? what kinda stuff is specified in there...

    and also how would i use sendmessage to send keydown event....

    heres what i got...
    Private Const WM_KEYDOWN = &H100

    SendMessage apphwnd, WM_KEYDOWN, 0, 0

    but what and where do i put if i want to call lets say H, E, L, L, O keys?
    No Comment.

  2. #2
    Megatron
    Guest
    wParam and lParam both contain message information.

    For example, to send H E L L O, you would use:
    VB Code:
    1. SendMessage hWindow, WM_KEYDOWN, vbKeyH, 0
    2. SendMessage hWindow, WM_KEYUP, vbKeyH, 0
    3. SendMessage hWindow, WM_KEYDOWN, vbKeyE, 0
    4. SendMessage hWindow, WM_KEYUP, vbKeyE, 0
    5. SendMessage hWindow, WM_KEYDOWN, vbKeyL, 0
    6. SendMessage hWindow, WM_KEYUP, vbKeyL, 0
    7. SendMessage hWindow, WM_KEYDOWN, vbKeyL, 0
    8. SendMessage hWindow, WM_KEYUP, vbKeyL, 0
    9. SendMessage hWindow, WM_KEYDOWN, vbKeyO, 0
    10. SendMessage hWindow, WM_KEYUP, vbKeyO, 0

  3. #3

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    thanx
    No Comment.

  4. #4

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    it gives me error 49
    bad dll calling convention

    on line

    SendMessage hWindow, WM_KEYDOWN, vbKeyH, 0
    No Comment.

  5. #5
    Megatron
    Guest
    Make sure you declare statement looks like this:
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

  6. #6

    Thread Starter
    Addicted Member FOOBAR's Avatar
    Join Date
    Aug 2000
    Posts
    172
    hmm, lol
    it gave me 5 e's

    i dont think anything is wrong with the code, i think it is just the app tring to recive it....

    its a game(half-life) in theconsole, i can type HELLO but if i do the code, i get eeeee

    any ideas on how to fix this?
    No Comment.

  7. #7
    Megatron
    Guest
    It's possible that the app your trying to send it to needs to recieve a WM_CHAR message as well. Try this:
    VB Code:
    1. SendMessage hWindow, WM_KEYDOWN, vbKeyH, 0
    2. SendMessage hWindow, WM_CHAR, vbKeyH, 0
    3. SendMessage hWindow, WM_KEYUP, vbKeyH, 0
    4. SendMessage hWindow, WM_KEYDOWN, vbKeyE, 0
    5. SendMessage hWindow, WM_CHAR, vbKeyE, 0
    6. SendMessage hWindow, WM_KEYUP, vbKeyE, 0
    7. SendMessage hWindow, WM_KEYDOWN, vbKeyL, 0
    8. SendMessage hWindow, WM_CHAR, vbKeyL, 0
    9. SendMessage hWindow, WM_KEYUP, vbKeyL, 0
    10. SendMessage hWindow, WM_KEYDOWN, vbKeyL, 0
    11. SendMessage hWindow, WM_CHAR, vbKeyL, 0
    12. SendMessage hWindow, WM_KEYUP, vbKeyL, 0
    13. SendMessage hWindow, WM_KEYDOWN, vbKeyO, 0
    14. SendMessage hWindow, WM_CHAR, vbKeyO, 0
    15. SendMessage hWindow, WM_KEYUP, vbKeyO, 0

  8. #8
    Megatron
    Guest
    You could also try a different (and shorter) approach by sending the WM_SETTEXT message.
    VB Code:
    1. sText = "Hello"
    2. SendMessage hWindow, WM_SETTEXT, 0, ByVal sText

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