微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

仅当鼠标位于屏幕的某个坐标处而不干扰我的键盘时,如何激活脚本?

如何解决仅当鼠标位于屏幕的某个坐标处而不干扰我的键盘时,如何激活脚本?

我编写了一个脚本,当鼠标坐标位于屏幕的最左侧或最右侧时,它可以让我将键盘的媒体快捷方式映射到我的鼠标 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,ypos
    If (xpos == 2559 || xpos == 0)
        Send {Media_Prev}
return

~MButton::
    MouseGetPos,ypos
    If (xpos == 2559 || xpos == 0)
        Send {Media_Play_Pause}
return

请注意,前面的 ~ 允许原始鼠标单击通过,因此通常右键单击时会出现上下文菜单。我添加了一个 SleepSend Escape 键来关闭 . . .嗯嗯

,

#If(docs) 就是为了这个。
你可以像这样使用它:

CoordMode,Screen

#If,MouseOnTheRight()
LButton::SendInput,{Media_Prev}
RButton::SendInput,{Media_Next}
MButton::SendInput,{Media_Play_Pause}
#If

MouseOnTheRight()
{
    MouseGetPos,x
    return x == A_ScreenWidth - 1
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。