VB6 - Way to simulate mouse mvmts similar to SENDKEYS

Thanks to earlier help from this board the SENDKEYS command was brought to my attention and I have been able to utilize it greatly. I was wondering if there is a way to send mouse movement commands to another windows program from my VB program? The 'Other' windows program needs to recognize these 'Sent' movements. Thanks for any help you can offer, Mike


Comments

  • The easiest way to send mouse messages from one program to another is by

    using the Windows API function PostMessage. Windows alerts any program to

    mouse movement within it's client area with the WM_MOUSEMOVE message.

    If you want to send mouse messages, just pretend you're Windows!


    The Declares you'd need:


    Const WM_MOUSEMOVE = &H200


    Declare Function PostMessage Lib "user32" Alias "PostMessageA" _

    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _

    ByVal lParam As Long) As Long


    You'd use it like:


    ret = PostMessage(hwnd, WM_MOUSEMOVE, wParam, lParam)


    --


    hwnd - is the handle to the window (program) you want to send to


    wParam - indicates whether various virtual keys are down. This can be any

    combination of the following values:

    Value Description

    MK_CONTROL Set if the CTRL key is down.

    MK_LBUTTON Set if the left mouse button is down.

    MK_MBUTTON Set if the middle mouse button is down.

    MK_RBUTTON Set if the right mouse button is down.

    MK_SHIFT Set if the SHIFT key is down.


    lParam - the low-order word specifies the x-coordinate of the mouse

    the high-order word specifies the y-coordinate of the mouse




    So...


    In the MouseMove event of the form you want to send the mouse movements from,

    you'd convert the arguments passed to the event into the PostMessage values

    and pass them on to the 'other' program.


    Of course, I've never tried this and you'd have to be careful because Windows

    is only expecting the program with the focus to be responding to mouse

    messages. Actually, I don't even know if it will work but it's the only way

    I can think of. Save your VB work before you test it out...


    I haven't given values for any of the MK_ constants (they're in the

    win32api.txt file), explained low word/high word or given the procedure to

    get the handle of any window so if you need that info, let me know.


    The BEST thing to do is go to www.altavista.com and search on win32.hlp. This

    file is the Win32 Programmer's Reference and it explains in GREAT detail

    (12MB worth) the main Windows API functions and how and where to use them.

    That's where I get all my answers ;)




    John




  • Thanks for the help John. It is very much appreciated. You have given me a lot too digest (my VB skills are not very strong yet) and I will certainly try this out as well as read and/or download the win32.hlp file. Thank you very much, Mike


    : The easiest way to send mouse messages from one program to another is by

    : using the Windows API function PostMessage. Windows alerts any program to

    : mouse movement within it's client area with the WM_MOUSEMOVE message.

    : If you want to send mouse messages, just pretend you're Windows!


    : The Declares you'd need:


    : Const WM_MOUSEMOVE = &H200


    : Declare Function PostMessage Lib "user32" Alias "PostMessageA" _

    : (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _

    : ByVal lParam As Long) As Long


    : You'd use it like:


    : ret = PostMessage(hwnd, WM_MOUSEMOVE, wParam, lParam)


    : --


    : hwnd - is the handle to the window (program) you want to send to


    : wParam - indicates whether various virtual keys are down. This can be any

    : combination of the following values:

    : Value Description

    : MK_CONTROL Set if the CTRL key is down.

    : MK_LBUTTON Set if the left mouse button is down.

    : MK_MBUTTON Set if the middle mouse button is down.

    : MK_RBUTTON Set if the right mouse button is down.

    : MK_SHIFT Set if the SHIFT key is down.


    : lParam - the low-order word specifies the x-coordinate of the mouse

    : the high-order word specifies the y-coordinate of the mouse


    :

    : So...


    : In the MouseMove event of the form you want to send the mouse movements from,

    : you'd convert the arguments passed to the event into the PostMessage values

    : and pass them on to the 'other' program.


    : Of course, I've never tried this and you'd have to be careful because Windows

    : is only expecting the program with the focus to be responding to mouse

    : messages. Actually, I don't even know if it will work but it's the only way

    : I can think of. Save your VB work before you test it out...


    : I haven't given values for any of the MK_ constants (they're in the

    : win32api.txt file), explained low word/high word or given the procedure to

    : get the handle of any window so if you need that info, let me know.


    : The BEST thing to do is go to www.altavista.com and search on win32.hlp. This

    : file is the Win32 Programmer's Reference and it explains in GREAT detail

    : (12MB worth) the main Windows API functions and how and where to use them.

    : That's where I get all my answers ;)


    :

    : John





  • No problem, glad I could help. One thing I forgot

    to say is that you can read the API help file

    online at


    http://msdn.microsoft.com/library/psdk/portals/win32start_1n6t.htm


    This is the latest version from the 'horse's mouth'.

    You could use this as a quick reference until you

    get your own copy.


    John




  • : No problem, glad I could help. One thing I forgot

    : to say is that you can read the API help file

    : online at


    : http://msdn.microsoft.com/library/psdk/portals/win32start_1n6t.htm


    : This is the latest version from the 'horse's mouth'.

    : You could use this as a quick reference until you

    : get your own copy.


    : John





  • Hey has anyone been about to get this to work. I have tried several ways and I can't get it to work. If someone has got it to work. Please post a example. Like with notepad or something. I have only been doing this visual basic stuff for about a year now. I'm just starting this api stuff. If you can't post the message please e-mail it to me.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories