且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Batch或PowerShell检查mouse \ keyboard是否处于活动状态

更新时间:2023-11-28 08:00:58

对于鼠标移动,您可以检查指针的位置并计算是否随时间变化.

As for the mouse movement, you could check the position of the pointer and calculate if there is a change over time.

$p1 = [System.Windows.Forms.Cursor]::Position
Start-Sleep -Seconds 5  # or use a shorter intervall with the -milliseconds parameter
$p2 = [System.Windows.Forms.Cursor]::Position
if($p1.X -eq $p2.X -and $p1.Y -eq $p2.Y) {
    "The mouse did not move"
} else {
    "The mouse moved"
}

对于密钥,您可能想尝试使用 get-keystroke脚本(基本上是键盘记录程序).

As for the keys, you might want to try a similar technique utilizing the get-keystroke script (which is basically a keylogger).