That Cursed Cursor….

While it isn’t April Fools yet – I been in a playful mood today, and while I was surfing the web my mouse kept playing up. I asked how do I get a new shiny mouse? I can’t, if it ain’t broken it won’t be replaced. This makes me grumpy.

When I was just about to jump up and down on my mouse to cause physical damage to the standard required, when I though that would be too easy to spot if it is in a few bits held together with duck tape! Plus it would mean that I would have to get up out of my chair and do something physical. My boss might get suspicious about that in its self! So I started to think is there a way I could emulate a iffy mouse???

How about if my cursor kept jumping all over the screen at random intervals, they might see that it is iffy and just sign off the order for a new better mouse. Now how should I go about doing this…. My first thoughts were to dust off the old Visual Studio and compile a small tray
program to do this little bit of software trickery… then I though, well I would just use C# anyway so why not do it in…. you guessed it!
Powershell.

So after a quick google on the internet I found that I could indeed access the cursor via the System.Windows.Forms namespace.

So with a quick control-C and control-V, and the basic commands to control the mouse were in my empty notepad soon to be a dot ps1 file :).

So now, I need to create a standard function – I love putting things in functions! I should perhaps consider using a workflow or something but meh! Quick and dirty at the moment! After all, Grumpy Admin is a lazy admin, and this really shouldn’t be taking up too much of my time! I am meant to be working!

So the code so far

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
Function Cursed-Cursor
{

}

Add-Type gives us access to the Assembly which has the namespace of the System.Windows.Forms so I can access all them useful functions.
The next line create an object from the virtualscreen object. There is lots of information I can drag and set from this but all we want to do is set the cursor position – the values that we set for the cursor should be in range of our screen or there could be problems! However, we also want them to be random. We can grab the bounds for the randomness  from the $screen object and combine it with the Get-Random cmdlet

So our code now looks like this

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
Function Cursed-Cursor
{
$x = get-random -maximum $screen.Width
$y = get-random -maximum $screen.Height
[Windows.Forms.Cursor]::Position = “$x,$y”
}

Excellent so – a quick test and this works. When you call the Cursed-Cursor function it jumps to a random inbound screen position – but it only does it the once – So we need to throw the action code  in a loop and then put a random gap between jumps. I want to see the effect quickly so I set the delay for a random period of 10 seconds using the sleep cmdlet.

So our final code looks like this

Add-Type -AssemblyName System.Windows.Forms
$screen = [System.Windows.Forms.SystemInformation]::

Function Cursed-Cursor
{

$i=1
do
{

$x = get-random -maximum $screen.Width
$y = get-random -maximum $screen.Height
$sleepdelay = get-random -maximum 10

[Windows.Forms.Cursor]::Position = “$x,$y”
sleep($sleepdelay)

}while ($i -eq 1)

}

Cursed-Cursor

That is great and works a treat, that new mouse should be here in a day or two 🙂 However,can still see the Powershell  command window which is a dead give away for this rodent like fraud that I want to pull off! So we need to launch our powershell script with the -windowstyle hidden parameter so it will be like this

powershell -file c:\cursed.ps1 -windowstyle hidden

You may then have to use task manager to kill the cursed-cursor process but there extra points up for grab if you use Powershell to kill the process.

Enjoy your new mouse guys or I will see you at the court house being done for click fraud!

Hazzy

Leave a Reply

Your email address will not be published. Required fields are marked *