autohotkey - AutoHotKey:MonitorCount 作为触发器?
问题描述
我希望我的 AutoHotKey 脚本不是由键盘快捷键触发,而是由一个事件触发,即每当我附加/分离第二个监视器时。我编写了这个小脚本,它正确地确定并显示了监视器的数量,但只有当我手动运行脚本时:
SysGet, MonitorCount, MonitorCount
if (MonitorCount<>lastMonitorCount)
{
MsgBox, Monitor Count:`t%MonitorCount%
}
SysGet, lastMonitorCount, MonitorCount
MsgBox
每当活动监视器的数量发生变化时,如何使显示自动出现?
解决方案
Set up a timer that will pop up the message box whenever the number of attached monitors changes:
#Persistent ; prevents the script from exiting when it reaches the 'Return'
SetTimer, DetectMonitorCount, 500 ; check every 500 milliseconds
DetectMonitorCount: ; this is a label
SysGet, MonitorCount, MonitorCount
if (MonitorCount <> lastMonitorCount)
MsgBox, Monitor Count:`t%MonitorCount%
SysGet, lastMonitorCount, MonitorCount
Return ; ends the subroutine
推荐阅读
- python - 关于使用 .replace 替换字符串
- pyspark - Windows 上的 Jupyter 笔记本 - 使用带有 kerberos 的 sparkmagic
- javascript - jQuery.extend() 和 Object.assign 失败
- r - R:当 `n` 很大时,使用 `(1 + 1 / n) ^ n` 逼近 `e = exp(1)` 会给出荒谬的结果
- android - 如何使用捆绑将 JPEG 图像传递给另一个活动?
- ios - iOS - Swift - AVPlayer:使用包含 khmer unicode 的 url 时出错
- python - Python 从 gzip 文件中读取 csv 行
- cakephp-3.0 - 无法保存数据但消息已保存
- sql - 将查询添加到现有查询以显示余额库存将是下个月的营业库存
- algorithm - 基于剩余空间将作业分配给主机的算法