使用Batch或PowerShell检查mouse \ keyboard是否处于活动状态 [英] Check if mouse\keyboard is active using Batch or PowerShell

查看:111
本文介绍了使用Batch或PowerShell检查mouse \ keyboard是否处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很长时间,找不到一个答案.

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

是否可以仅使用BatchPowerShell脚本检查是否正在使用我的鼠标或键盘(当前正在移动鼠标或正在按下键)?如果是,怎么办?

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?

推荐答案

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

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).

这篇关于使用Batch或PowerShell检查mouse \ keyboard是否处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆