简体   繁体   中英

In AutoHotKey, how do I block LButton from being sent if it's used in the hotkey context but not if it's used elsewhere?

I have this script:

~LButton & RButton::
    Click Middle
Return

Supposedly when I press LButton and RButton together, they'll work as the MButton . This does work but it sends the LButton as well. If I remove the ~ from the hotkey prefix, LButton stops working altogether.

I've tried various ways to try and make it work.

This does not work:

#If GetKeyState("LButton", "P")
RButton::
    Click Middle
Return

This doesn't work either:

middleclicktrigger := False

LButton & RButton::
    middleclicktrigger := True
    Click Middle
    middleclicktrigger := False
Return

~LButton::
    If (middleclicktrigger) {
        BlockInput, Mouse
    }
Return

This supposedly works but I encountered a problem where I cannot hold and drag the LButton with normal usage. It works fine with simple left clicking but I need it to work as a normal left mouse button when it's not being used along with the right mouse button in a hotkey combination:

middleclicktrigger := False

LButton & RButton::
    middleclicktrigger := True
    Click Middle
    middleclicktrigger := False
Return

LButton::
    IF (!middleclicktrigger) {
        Click down
    }
Return

LButton up::
    IF (!middleclicktrigger) {
        Click up
    }
Return

Okay, I solved it in the most convoluted way possible. If you have a cleaner approach to this, please do give it to me because I don't feel comfortable with this but it works so heh.

middleclick := False
leftclick := False
rightclick := False

Loop {
    If (GetKeyState("LButton", "P") && GetKeyState("RButton", "P") && !middleclick) {
        middleclick := True
        BlockInput, Mouse
        Click Middle
        SetTimer, middleclickfalse, -1000
    } Else If (GetKeyState("LButton", "P") && !leftclick && !middleclick) {
        leftclick := True
        Click down
    } Else If (GetKeyState("RButton", "P") && !rightclick && !middleclick) {
        rightclick := True
        Click down right
    }

    Sleep, 10
}

middleclickfalse:
    middleclick := False
Return

LButton up::
    If (!middleclick) {
        If (leftclick) {
            Click up
            leftclick := False
        }
    }
Return

RButton up::
    If (!middleclick) {
        If (rightclick) {
            Click up right
            rightclick := False
        }
    }
Return

Someone Stumbling upon this, Read this first.

The one who posted this question was close but...

The concise answer

RButton::
if GetKeyState("LButton", "P")
Click Middle
else
Click r
Return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM