Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wiggling the mouse

Tags:

c#

winapi

mouse

OK. This is a bit of a vanity app, but I had a situation today at work where I was in a training class and the machine was set to lock every 10 minutes. Well, if the trainers got excited about talking - as opposed to changing slides - the machine would lock up.

I'd like to write a teeny app that has nothing but a taskbar icon that does nothing but move the mouse by 1 pixel every 4 minutes.

I can do that in 3 ways with Delphi (my strong language) but I'm moving to C# for work and I'd like to know the path of least resistance there.

like image 390
Bruce the Hoon Avatar asked Aug 05 '08 02:08

Bruce the Hoon


People also ask

What is a wiggle mouse?

WiggleMouse is a cross platform java program that will wiggle the mouse at an interval entered by the user through a gui.

How do you jiggle a mouse?

As for Mouse Jiggler, same deal -- but with your cursor. Just run the tiny app as needed and click Enable Jiggle. After a couple seconds, you'll see your pointer start to, well, jiggle.

Why does my mouse wiggle?

Once the mouse is acting erratically, possible reason could be due to the mouse is not clean, the optical portion of the mouse is blocked, it's being placed on a bad surface, bad wireless connection or it has a failing batteries and there's a moisture or a liquid substance on finger while using the touchpad.

Can my employer detect a Mouse Jiggler?

The contraptions, also dubbed 'mouse jigglers,' effectively allow users to escape their desks for hours at a time without being detected by their employer by moving their mouse autonomously.


2 Answers

for C# 3.5

without notifyicon therefore you will need to terminate this application in task manager manually

using System; using System.Drawing; using System.Windows.Forms;  static class Program {     static void Main()     {         Timer timer = new Timer();         // timer.Interval = 4 minutes         timer.Interval = (int)(TimeSpan.TicksPerMinute * 4 / TimeSpan.TicksPerMillisecond);         timer.Tick += (sender, args) => { Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y + 1); };         timer.Start();         Application.Run();     } } 
like image 67
lubos hasko Avatar answered Oct 04 '22 15:10

lubos hasko


The "correct" way to do this is to respond to the WM_SYSCOMMAND message. In C# this looks something like this:

protected override void WndProc(ref Message m) {     // Abort screensaver and monitor power-down     const int WM_SYSCOMMAND = 0x0112;     const int SC_MONITOR_POWER = 0xF170;     const int SC_SCREENSAVE = 0xF140;     int WParam = (m.WParam.ToInt32() & 0xFFF0);      if (m.Msg == WM_SYSCOMMAND &&         (WParam == SC_MONITOR_POWER || WParam == SC_SCREENSAVE)) return;      base.WndProc(ref m); } 

According to MSDN, if the screensaver password is enabled by policy on Vista or above, this won't work. Presumably programmatically moving the mouse is also ignored, though I have not tested this.

like image 27
Zooba Avatar answered Oct 04 '22 15:10

Zooba