Jump to content
phi7ip

WM_Mousemove not moving

Recommended Posts

Hi, have been banging my head against a wall for days everything I can find says that this should work but for the life of me can't get it to work

I'm trying to automate the testing of an app in the background, which requires "drags" but when I execute this it registers as two separate events not a single drag

I also tried testing it in paint and nothing happens when it should draw a ine

Any input would be appreciated xx

Func Mousedrag($x1,$y1,$x2,$y2)
    Local $WM_MOUSEMOVE     =  0x0200
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202

    _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hwnd, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hwnd, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc

 

Share this post


Link to post
Share on other sites

That would work but i'm trying to automate it so it can run in the background

 

Thanks for the quick reply, I regularly visit the forums but try to solve my problems just by searching but this one has just got me stumped.

Share this post


Link to post
Share on other sites
6 minutes ago, Nine said:

Producing only a func as code is hardly helpful.  Maybe you should give a runable script that expresses precisely the problem you are facing.

Sorry here's some runable script, which should draw a straight line (given you have the brush tool selected) but instead nothing happens

#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
$hWnd = WinWait("Untitled - Paint")


Func Mousedrag($x1,$y1,$x2,$y2)
    Local $WM_MOUSEMOVE     =  0x0200
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202

    _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hwnd, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hwnd, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc

Mousedrag(484,554,732,554)

 

Share this post


Link to post
Share on other sites

The messages that you send to Paint need to be treated in a WindowProc function.  Like all messages it is a notification not an order.  So it all depends if the application captures the message and do something with it.  In the case of Paint it looks like it does not.  Take a look at this example in MSDN, that is quite close to what you want to achieve :

https://docs.microsoft.com/fr-ca/windows/desktop/inputdev/using-mouse-input#drawing-lines-with-the-mouse

You can see how this particular application captures the messages, but actually do something with it...

Share this post


Link to post
Share on other sites

Does that mean its not possible? and does that only apply to mousemove? which would explain why its only picking up the two mousedown and up commands

Share this post


Link to post
Share on other sites

Paint is not picking anything (win 7).  I tested it with fill.  It would clearly splash black all over the screen if it was capturing any mouse down.  Yes it means it is not possible to send those messages to Paint.  But why would you want to send background messages to Paint ?  I am curious to understand the purpose of this.

Share this post


Link to post
Share on other sites

I was using paint as an easy way to test it that was easily accessible, I'm trying to automate testing of a mobile app which I'm runnning in an emulator (nox).

I set it to show "touches" I can see two separate touches for the mousedown and up but not a drag connecting them

Share this post


Link to post
Share on other sites
Posted (edited)

The _WinAPI_Mouse_Event() is something that should be used for this

Didn't try anything to workout the $x $y for accuracy The *65535 is used a hack taken from here

#include <WinAPISys.au3>
#include <WinAPIRes.au3>

$hWnd = WinActivate("[CLASS:MSPaintApp]")
WinMove($hWnd, "", 0, 0, 600, 600)
$aPos = WinGetPos($hWnd)
$aCPos = ControlGetPos($hWnd, "", "[CLASS:MSPaintView]")
$aPos[1] += $aCPos[1]
_MouseDraw($aPos[0], $aPos[1])

Func _MouseDraw($x1, $y1)
    $x = $x1 * 65535 / @DesktopWidth + 2500
    $y = $y1 * 65535 / @DesktopHeight + 1500
    _WinAPI_Mouse_Event(BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_MOVE), $x, $y)
    For $j = 0 To 1
        For $i = 1 To 20
            If $j Then _WinAPI_Mouse_Event(BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_MOVE), $x, $y)
            _WinAPI_Mouse_Event(BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_LEFTDOWN), $x, $y)
            _WinAPI_Mouse_Event(BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_MOVE), $x + 12000, $y + ($i * 1100))
            _WinAPI_Mouse_Event(BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_LEFTUP), $x, $y)
        Next
    Next
    _WinAPI_Mouse_Event(BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_MOVE), $x, $y)
EndFunc   ;==>_MouseDraw

Deye

Edited by Deye

Share this post


Link to post
Share on other sites

Note that the function in first post actually does work in Paint, but you must use the handle of the image control (not the handle of the Paint window).

Share this post


Link to post
Share on other sites

@Nine Inhouse apps, I just need a way to predictably drag I tried using a  mousescroll but its too imprecise as its like a fling rather than a drag

@LarsJ Excuse my ignorance as I've only ever used titles I tried this but cant  seem to get it to work
 

#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
$hWnd = WinWait("[HANDLE:0x00130EA4]", "")

Func Mousedrag($x1,$y1,$x2,$y2)
    Local $WM_MOUSEMOVE     =  0x0200
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202

    _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hwnd, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hwnd, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hwnd, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc

Mousedrag(484,554,732,554)

 

Share this post


Link to post
Share on other sites
#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
$hWnd = WinWait("Untitled - Paint")
$hControl = ControlGetHandle($hWnd, "", "Afx:00007FF78D1E0000:81")



Func Mousedrag($x1, $y1, $x2, $y2)
    Local $WM_MOUSEMOVE   = 0x0200
    Local $MK_LBUTTON     = 0x0001
    Local $WM_LBUTTONDOWN = 0x0201
    Local $WM_LBUTTONUP   = 0x0202

    _SendMessage($hControl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hControl, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hControl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hControl, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc   ;==>Mousedrag

Mousedrag(484, 554, 732, 554)
ConsoleWrite($hWnd & @LF & $hControl & @LF)

Coords relevant to the control

Share this post


Link to post
Share on other sites
Posted (edited)
5 hours ago, Nine said:

@badcoder123 Control changes at every new instance of paint, it needs to be a regexp.  Anyway he doesn't want to implement this in Paint, it is for an "In-house apps"...

I believe Nox only uses 1 control for its emulation (control bar, window options being different) so this would work for its base control if you +posx and +posy for the window borders. Not certain but I'm believe it does only has one control

Edited by badcoder123

Share this post


Link to post
Share on other sites

I think the target is not the problem as the mousedown and up are registering for that i am just using the window title  and offsetting the coordinates by 2 & 30px.

for some reason it just seams to not be registering the mousemove commands, 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...