简体   繁体   中英

How to prevent third party apps from detecting user idleness?

In Discord there is no option to disable idle detection, so i want to write a little app which simulates user so that discord and other apps don't think I'm idle.

I've tried using Cursor. Position and that teleports the mouse around on the screen but it does not prevent idle detection.

How can i simulate user input in c# windows forms application so as to fool idle detection in discord and other apps?

I ended up going with the following line of code. This just sends alt+tab to windows. Works for my purposes though a less disruptive approach would be preferable, like maybe a windows click or something.

SendKeys.SendWait("%({tab})");

The code below in the button Click event could be placed into Timer.Tick event which toggles scroll lock button.

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace StackOverflow_PressScrollLock
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern void keybd_event(
            byte bVk, 
            byte bScan, 
            uint dwFlags, 
            UIntPtr dwExtraInfo);

        public Form1()
        {
            InitializeComponent();
        }
        private static void PressScrollLock()
        {
            const byte vkScroll = 0x91;
            const byte keyeventfKeyup = 0x2;

            keybd_event(vkScroll, 0x45, 0, (UIntPtr)0);
            keybd_event(vkScroll, 0x45, keyeventfKeyup, (UIntPtr)0);
        }
        /// <summary>
        /// This would go in a Timer.Tick event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExecuteButton_Click(object sender, EventArgs e)
        {
            PressScrollLock();
            PressScrollLock();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM