How to Drag & Drop with Powershell ps1 script?
How to Drag & Drop with Powershell ps1 script?
I have a simple program that has drag & drop functionality.
I want to drag from pixel point (x1,y1) to pixel point (x2,y2) and release the mouse.
How can I automate this with Powershell?
Following this basic tutorial, I can open the program and sendkeys.. but how to drag/drop?
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
Notepad
start-sleep -Milliseconds 500
#[Microsoft.VisualBasic.Interaction]::AppActivate("GUI_APP_I_USE")
[Microsoft.VisualBasic.Interaction]::AppActivate("Notepad")
[System.Windows.Forms.SendKeys]::SendWait("Hello")
#[Some.Library.I.Drag.Drop.With]::DragStart(x1,y1)
#[Some.Library.I.Drag.Drop.With]::DragEnd(x2,y2)
1 Answer
1
I don't think you should be looking into dragging and dropping. Instead, you can detect a mousedown event and a mouseup event which would be the same as a drag and drop.
So you click on the pixel (MouseDown), get its color and drag it around. When you drop it (MouseUp), you update the new pixel location with the color, and remove it from the old location.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy