使用批处理或PowerShell检查鼠标\键盘是否处于活动状态
我已经找了很长时间了,找不到一个答案使用批处理或PowerShell检查鼠标\键盘是否处于活动状态,powershell,batch-file,keyboard,mouse,Powershell,Batch File,Keyboard,Mouse,我已经找了很长时间了,找不到一个答案 是否可以仅使用Batch或PowerShell脚本检查我的鼠标或键盘是否正在使用(鼠标当前正在移动或按键正在按下)?如果是,如何移动?关于鼠标移动,您可以检查指针的位置,并计算是否随时间发生变化 $p1 = [System.Windows.Forms.Cursor]::Position Start-Sleep -Seconds 5 # or use a shorter intervall with the -milliseconds parameter $
是否可以仅使用
Batch
或PowerShell
脚本检查我的鼠标或键盘是否正在使用(鼠标当前正在移动或按键正在按下)?如果是,如何移动?关于鼠标移动,您可以检查指针的位置,并计算是否随时间发生变化
$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"
}
至于按键,您可能希望尝试使用类似的技术(基本上是键盘记录器)。您正在尝试确定鼠标当前是否正在移动或按键是否正在按下?完全正确!我将把这一点补充到问题中。