Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用批处理或PowerShell检查鼠标\键盘是否处于活动状态_Powershell_Batch File_Keyboard_Mouse - Fatal编程技术网

使用批处理或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"
}

至于按键,您可能希望尝试使用类似的技术(基本上是键盘记录器)。

您正在尝试确定鼠标当前是否正在移动或按键是否正在按下?完全正确!我将把这一点补充到问题中。