Check if mouse\keyboard is active using Batch or PowerShell

一个人想着一个人 提交于 2019-12-08 05:34:04

问题


I have been searching for this for a long time, and can't find one single answer.

Is it possible to check if my mouse or keyboard is in use (the mouse is currently moving or keys are being pressed) using only a Batch or PowerShell script? If yes, how?


回答1:


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"
}

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



来源:https://stackoverflow.com/questions/35124097/check-if-mouse-keyboard-is-active-using-batch-or-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!