Shaking the mouse

OK. This is a little a vanity application, yet I had a scenario today at the workplace where I remained in a training class and also the equipment was readied to lock every 10 mins. Well, if the instructors obtained delighted concerning chatting - in contrast to transforming slides - the equipment would certainly secure.

I would certainly such as to write a teensy application that has just a taskbar symbol that not does anything yet relocate the mouse by 1 pixel every 4 mins.

I can do that in 3 means with Delphi (my solid language) yet I'm relocating to C# for job and also I would certainly such as to recognize the course of the very least resistance there.

0
2019-05-03 23:56:12
Source Share
Answers: 3

The "correct" means to do this is to reply to the WM_SYSCOMMAND message. In C# this looks something similar to 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 made it possible for by plan on Vista or above, this will not function. Probably programmatically relocating the mouse is additionally overlooked, though I have actually not examined this.

0
2019-12-03 04:18:22
Source

for C# 3.5

without notifyicon consequently you will certainly require to end this application in job supervisor by hand

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();
    }
}
0
2019-05-07 17:33:40
Source

Something similar to this needs to function (however, you will certainly intend to transform the period ).

public Form1()
{
    InitializeComponent();
    Timer Every4Minutes = new Timer();
    Every4Minutes.Interval = 10;
    Every4Minutes.Tick += new EventHandler(MoveNow);
    Every4Minutes.Start();
}

void MoveNow(object sender, EventArgs e)
{
    Cursor.Position = new Point(Cursor.Position.X - 1, Cursor.Position.Y - 1);
}
0
2019-05-07 17:09:18
Source