
Anti-idle apps for Microsoft Teams and the like are a dime a dozen, but how about creating your own? In this article, I’ll show you how to create an anti-idle app for Microsoft Teams using .NET and C#.
Idle Detection
Idle detection is as simple as it is annoying: it simply reacts to user input. If the user does not look at the screen for a while, the status is set to “absent”. But you are not always really absent, sometimes you are just sitting in front of your computer and writing something down on a piece of paper, but Teams thinks you are lying in bed and sets you to absent.
Anti-Idle
The Anti-Idle app is a small application that simulates a user input at regular intervals. This can be a mouse click or a keyboard input. In our case, we simply use the Windows API to send a new position for the mouse cursor.
The application
First we need a .NET console application whose project settings we set as follows:
1<Project Sdk="Microsoft.NET.Sdk">
2
3 <PropertyGroup>
4 <OutputType>Exe</OutputType>
5 <TargetFramework>net8.0-windows</TargetFramework>
6 <ImplicitUsings>enable</ImplicitUsings>
7 <Nullable>enable</Nullable>
8 <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9 </PropertyGroup>
10
11</Project>
This defines that we want to create a console application for .NET 8. More precisely, specifically for Windows, as in our case we need to address the Windows API directly.
Now we only need the code that moves the cursor at regular intervals, whereby I have decided to reset the cursor to the original point after setting the cursor.
1using System.Runtime.InteropServices;
2
3namespace BenjaminAbt.AntiIdleApp;
4
5internal partial class Program
6{
7 // Import the Windows API functions to control the mouse position
8 [LibraryImport("user32.dll")]
9 [return: MarshalAs(UnmanagedType.Bool)]
10 public static partial bool SetCursorPos(int X, int Y);
11
12 [LibraryImport("user32.dll")]
13 [return: MarshalAs(UnmanagedType.Bool)]
14 public static partial bool GetCursorPos(out POINT lpPoint);
15
16 // Structure to store the mouse position
17 public struct POINT
18 {
19 public int X;
20 public int Y;
21 }
22
23 public static async Task Main(string[] args)
24 {
25 Console.WriteLine("Anti Idle is running. Press CTRL+C to exit.");
26
27 // Create a PeriodicTimer that ticks every 1 minute (60 seconds)
28 using PeriodicTimer timer = new(TimeSpan.FromMinutes(1));
29
30 // Loop that waits for each tick of the timer
31 while (await timer.WaitForNextTickAsync())
32 {
33 // Get the current mouse position
34 if (GetCursorPos(out POINT currentPos))
35 {
36 // Move the mouse cursor 1 pixel to the right
37 SetCursorPos(currentPos.X + 1, currentPos.Y);
38
39 // Short delay to ensure the movement is registered
40 await Task.Delay(50);
41
42 // Move the mouse back to the original position
43 SetCursorPos(currentPos.X, currentPos.Y);
44 }
45 }
46 }
47}
Our Microsoft Teams anti-idle app is ready.
The complete code is available at https://github.com/BenjaminAbt/dotnet-anti-idle-app .
Related articles

Feb 10, 2025 - 2 min read
Create QRCodes with .NET and ZXing
QR Codes are a very popular way to pass on information - for example an URL. The QR code can be placed on all kinds of places, for example …

Feb 04, 2025 - 3 min read
Create an Entra Local User Account via Microsoft Graph with .NET
The Microsoft Graph and Entra documentation are both very comprehensive and provide a lot of information - but they often contain no …

Jan 20, 2025 - 4 min read
The power of Aggressive Inlining in .NET and C#
If you browse through certain libraries or the .NET Runtime from time to time, you will notice that the attribute …
Let's Work Together
Looking for an experienced Platform Architect or Engineer for your next project? Whether it's cloud migration, platform modernization or building new solutions from scratch - I'm here to help you succeed.
