How to keep an RDP session alive?

The following script uses the free AutoHotkey.

The script checks every 10 minutes (600000 milliseconds) for computer inactivity. It then searches for all Remote Desktop windows by title, and for each it will set the RDP window to be the active window and will send it a click in the middle of its screen and for good measure the Enter key.

SetTitleMatchMode, 2
Loop
{
    if A_TimeIdle >= 600000
    {
        WinGet, id, List, Remote Desktop Connection
        Loop, %id%
        {
            this_id := id%A_Index%
            WinGetTitle, this_title, ahk_id %this_id%
            TrayTip, Found RDP session, %this_title%, 2, 17
            ControlSend , , {Enter}, ahk_id %this_id%
        }
    }
    Sleep, 600000
}
return

This script was tested on a Windows 10 computer with RDP to a Windows 10 VM. For some unknown reason, AutoHotkey is unable to re-minimize the RDP window and re-activate the previously active window, so RDP stays active.

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.