phi7ip Posted April 20, 2019 Share Posted April 20, 2019 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 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 20, 2019 Moderators Share Posted April 20, 2019 @phi7ip welcome to the forum. Have you tried just MouseClickDrag? This works great for drawing a line in paint: MouseClickDrag("left", 100, 200, 400, 400) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
phi7ip Posted April 20, 2019 Author Share Posted April 20, 2019 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. Link to comment Share on other sites More sharing options...
Nine Posted April 20, 2019 Share Posted April 20, 2019 Producing only a func as code is hardly helpful. Maybe you should give a runable script that expresses precisely the problem you are facing. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
phi7ip Posted April 20, 2019 Author Share Posted April 20, 2019 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) Link to comment Share on other sites More sharing options...
Nine Posted April 21, 2019 Share Posted April 21, 2019 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... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
phi7ip Posted April 21, 2019 Author Share Posted April 21, 2019 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 Link to comment Share on other sites More sharing options...
Nine Posted April 21, 2019 Share Posted April 21, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
phi7ip Posted April 21, 2019 Author Share Posted April 21, 2019 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 Link to comment Share on other sites More sharing options...
Deye Posted April 22, 2019 Share Posted April 22, 2019 (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 April 22, 2019 by Deye Link to comment Share on other sites More sharing options...
phi7ip Posted April 23, 2019 Author Share Posted April 23, 2019 @Deye Thanks this is excatly what I need but it needs to run in the background Link to comment Share on other sites More sharing options...
Nine Posted April 23, 2019 Share Posted April 23, 2019 On 4/21/2019 at 2:27 PM, phi7ip said: I'm trying to automate testing of a mobile app which I'm runnning in an emulator (nox). Can you tell us what is the application you are trying to run under nox ? “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
LarsJ Posted April 23, 2019 Share Posted April 23, 2019 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). Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
phi7ip Posted April 23, 2019 Author Share Posted April 23, 2019 @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) Link to comment Share on other sites More sharing options...
Zedna Posted April 23, 2019 Share Posted April 23, 2019 Look at function ControlGetHandle() badcoder123 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
badcoder123 Posted April 24, 2019 Share Posted April 24, 2019 #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 Link to comment Share on other sites More sharing options...
Nine Posted April 24, 2019 Share Posted April 24, 2019 @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"... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
badcoder123 Posted April 24, 2019 Share Posted April 24, 2019 (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 April 24, 2019 by badcoder123 Link to comment Share on other sites More sharing options...
phi7ip Posted April 25, 2019 Author Share Posted April 25, 2019 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, Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now