Simulate mouse movement and click

Dec 11, 2014 at 2:55 PM
Is this possible.

track a mouse movement and button click state in a list form
so you would have something like this.

goto Application Windows

1 Left Click Mouse and move to Coordinates X, Y

2 Left Click Mouse and move to Coordinates X, Y

3 move to Coordinates X, Y and right click

That would be an awesome feature

Or can I do that already via scripting, if yes could you let me know how it is done.
Coordinator
Dec 11, 2014 at 3:23 PM
Tracking mouse activity from PowerShell isn't going to be straight-forward, but simulating mouse movement isn't too difficult:
$MouseEventSig=@' 
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@ 
$MouseEvent = Add-Type -memberDefinition $MouseEventSig -name "MouseEventWinApi" -passThru
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(100,100)
$MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0);
$MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0);
Start-Sleep -Milliseconds 500
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(200,200)
$MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0);
$MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0);
Start-Sleep -Milliseconds 500
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(300,300)
$MouseEvent::mouse_event(0x00000008, 0, 0, 0, 0);
$MouseEvent::mouse_event(0x00000010, 0, 0, 0, 0);
Moves too 100,100 - left click - moves to 200,200 - left click - moves to 300,300 - right click.

I've put a half a second pause in between moves so that you can see it happen.
Marked as answer by sw3103 on 1/26/2015 at 4:54 PM
Dec 11, 2014 at 3:52 PM
Thank you for the quick reply, thats really awesome.

Maybe in the future release you could implement it along the lines like this
http://www.murgee.com/auto-mouse-click/images/auto-mouse-click.jpg

for people without coding skills
Jan 23, 2015 at 6:10 AM
Facing issue , Please help:
I have opened a word document and tried movemouse.exe
After every 3 seconds the mouse pointer moves to a new location
And clicks that point . Whereas the mouse pointer should remain fixed
To a fixed position x 295, y 635
Settings done:
  1. Actions tab:
    a. 3 seconds interval
    b. Static mouse pointer position x 295 635 y .
    c. Click left mouse button
    No other setting is enabled .
Coordinator
Jan 26, 2015 at 11:47 PM
Move Mouse only moves the pointer at the very beginning, not at each interval. If the mouse pointer is moved during operation, it will be clicked at whichever position the pointer is at when the interval arrives.

You have no other settings or scripts enabled?

Sep 3, 2015 at 2:55 AM
Edited Sep 3, 2015 at 2:56 AM
Hello, when I try to execute the above script and click on show script execution it tells me that System.Drawing.Point couldn't be found.
CategoryInfo : InvalidType: <:> [New-Object], PSArgumentException
FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands:NewObjectCommand.

I was looking at that murgee.com site but I've read that there is a keylogger with the installation of the auto-mouse-click programm. Digging deeper some sources say it's clean but I'd rather use a programm that I've already installed and deemed thrushworthy. Good lord, now I've become paranoid:
https://www.herdprotect.com/movemouse.exe-e90e1188baee2954415914c83d07b2392430171f.aspx
say that movemouse.exe is malware.

No clue what that's all about.
I am sorry if i am just stirring up dust here due to my slight internet paranoia.
Coordinator
Sep 5, 2015 at 8:22 AM
Try this updated script:
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$MouseEventSig=@' 
[DllImport("user32.dll",CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo);
'@ 
$MouseEvent = Add-Type -memberDefinition $MouseEventSig -name "MouseEventWinApi" -passThru
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(100,100)
$MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0);
$MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0);
Start-Sleep -Milliseconds 500
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(200,200)
$MouseEvent::mouse_event(0x00000002, 0, 0, 0, 0);
$MouseEvent::mouse_event(0x00000004, 0, 0, 0, 0);
Start-Sleep -Milliseconds 500
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(300,300)
$MouseEvent::mouse_event(0x00000008, 0, 0, 0, 0);
$MouseEvent::mouse_event(0x00000010, 0, 0, 0, 0);
As for the malware detection, I can only remind people that Move Mouse is an open source project, and every line of code can be viewed here:

http://movemouse.codeplex.com/SourceControl/latest

I know not everyone that uses Move Mouse will necessarily be able to understand the source code, although it has been downloaded nearly 300k times since it was first released six years ago, so I'm sure any malware issues would have been called out long ago.
Sep 13, 2015 at 12:22 AM
Edited Sep 13, 2015 at 7:31 AM
Thank you for your answer. It works perfectly now. :)
Yes, shortly after I cooled down and looked for any other virus warnings related to move mouse and found next to nothing. (after looking at it a bit closer it seemed that the infected file herdprotect warned about was copyrighted by Dell Inc. so i doubt it was this one in any case)

Also I wonder if you could give me an example of the code needed for keystrokes. and maybe a way to randomize the Start-Sleep thing as in like between 2 and 5 seconds waiting time. That would be pretty awesome.

Cheers,
Mykes
Coordinator
Sep 14, 2015 at 10:08 AM
There is a PowerShell and VB Script example on the Script Examples page:

https://movemouse.codeplex.com/wikipage?title=Script%20Examples