Teams挂机脚本

为保证Teams可以显示为一直在线,制作出该脚本
按CTRL c退出
可兼容windows自带powershell

# MoveMouseLoop.ps1
# 加载 Windows Forms 程序集
Add-Type -AssemblyName System.Windows.Forms

# 加载鼠标移动功能
Add-Type -TypeDefinition @'
using System;
using System.Runtime.InteropServices;

public class MouseMover {
    [DllImport("user32.dll")]
    public static extern bool SetCursorPos(int X, int Y);
}
'@

# 检查 PowerShell 版本
if ($PSVersionTable.PSVersion.Major -lt 5) {
    Write-Host "This script requires PowerShell 5.0 or later." -ForegroundColor Red
    exit
}

try {
    Write-Host "Press Ctrl+C to stop the script..."
    while ($true) {
        # 获取屏幕分辨率
        $screenWidth = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Width
        $screenHeight = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds.Height

        # 检查屏幕分辨率是否加载正确
        if (-not $screenWidth -or -not $screenHeight) {
            throw "Failed to get screen resolution."
        }

        # 随机生成鼠标移动位置
        $x = Get-Random -Minimum 0 -Maximum $screenWidth
        $y = Get-Random -Minimum 0 -Maximum $screenHeight

        # 移动鼠标到随机位置
        $success = [MouseMover]::SetCursorPos($x, $y)
        if (-not $success) {
            throw "Failed to move the mouse to ($x, $y)."
        }

        Write-Host "Mouse moved to: ($x, $y)"

        # 每次移动后等待1秒
        Start-Sleep -Seconds 1
    }
} catch {
    Write-Host "An error occurred: $($_.Exception.Message)" -ForegroundColor Red
    Write-Host "Script stopped. Exiting..." -ForegroundColor Yellow
}
posted @ 2024-12-13 12:23  Dreaife  阅读(193)  评论(0)    收藏  举报