autohotkey - 仅当鼠标位于屏幕的某个坐标而不干扰我的键盘时,如何才能激活脚本?
问题描述
我编写了一个脚本,当鼠标坐标位于屏幕的最左侧或最右侧时,我可以将键盘的媒体快捷方式映射到鼠标 LRM 按钮。虽然它确实有效,但我有奇怪的副作用:
- 当我打开大写锁定时,字母很少会变成小写。
- 当我长时间使用 shift 输入大写字母时,这将打开大写锁定
使用键盘历史记录,我看到我的脚本不断发送“Alt Up”键,我这样做是为了释放“Alt Down”状态,但有些东西是关闭的。
我的目标是在鼠标悬停在某个坐标上时发送一个修饰键,这样当我用该鼠标按钮单击时,它会启动另一个 ahk 编程的快捷方式。但无法弄清楚我的代码或思考过程中的逻辑错误在哪里。
这是脚本:
; ------------------------
; Global Initializers
#InstallKeybdHook
#MaxThreadsPerHotkey 1
; ---------------------
; Control Spotify; position your mouse top-most edge and use L/M/R-mouse keys.
SetTimer, WatchCursorx, 1000
return
WatchCursorx:
CoordMode, Mouse, Screen
MouseGetPos, xpos, ypos
;Based on location of the mouse simulate shortcut activation
If (xpos == 2559 || xpos == 0)
{
Send {Alt Down}
}
Else
{
Send {Alt Up}
}
return
;Define shortcuts mentioned above
!RButton::
Send {Media_Next}
return
!LButton::
Send {Media_Prev}
return
!MButton::
send {Media_Play_Pause}
return
解决方案
根据我的评论,试试这样:
CoordMode, Mouse, Screen
~RButton::
MouseGetPos, xpos, ypos
If (xpos == 2559 || xpos == 0)
{
Send {Media_Next}
sleep, 500
Send {esc} ' this gets rid of right context menu
}
return
~LButton::
MouseGetPos, xpos, ypos
If (xpos == 2559 || xpos == 0)
Send {Media_Prev}
return
~MButton::
MouseGetPos, xpos, ypos
If (xpos == 2559 || xpos == 0)
Send {Media_Play_Pause}
return
请注意,前面~
是让原始鼠标单击通过,因此通常右键单击时会出现上下文菜单。我添加了一个Sleep
andSend Escape
键来关闭。. . ymmv
推荐阅读
- c++ - 如何在 Clion 中检查函数原型的返回值类型?
- c# - MVC Model.Any System.ArgumentNullException
- java - 接收方不可用时 ActiveMQ 消息丢失
- r - 如何在 Ui 中返回服务器对象?
- javascript - 单击按钮时无法将值传递给函数
- elasticsearch - 如何使用匹配的_version查询父/子关系?
- javascript - 添加到购物车
- javascript - 当单击从父组件传递时,为什么子组件未定义“this”?
- regex - Environment Modules: is-loaded 可以查找一系列模块文件名吗?
- python - 获取特定 NCT ID 历史记录的临床试验