Autohotkey KeyWait,如何使用OR(||)


0

宏看起来没有“ OR MButton”就可以工作。如何同时使用两者?

Loop
{
    KeyWait, RButton OR MButton
    KeyWait, RButton OR MButton, D
    CoordMode, Pixel, Window
    PixelSearch, FoundX, FoundY, 258, 762, 258, 762, 0x000402, 0, Fast RGB
    If ErrorLevel
        Break
    If ErrorLevel = 0
    {
        Send, {2}
        Sleep, 200
    }
}

1
您是否要在按下其中一个按钮之后,之后或同时执行PixelSearch?
user3419297

不能查看[documentation],因为唯一预期的参数是一个键。您可能需要一个独立的循环来检查常规按键,并检查是否要对它进行响应。
赛斯

如果按RButton,发送2。如果按MButton,发送2。PixelSearch可以控制{2}是否免费。什么样的循环?
马可波罗

Answers:


1

看来您实际上不需要循环(??)。

您是否只想触发RButtonMButton,然后每次点击执行一次?

~RButton::MyFunction()  ; Remove ~ to make these calls block the clicks from passing through
~MButton::MyFunction()  ; otherwise, leave in place to block clicks and send "2" instead

MyFunction() {
    PixelSearch, FoundX, FoundY, 258, 762, 258, 762, 0x000402, 0, Fast RGB
    If ErrorLevel
        Return

    Send, 2         ; Else if ErrorLevel was = 0, send "2"... shouldn't need brackets unless sending a special key
    ;Sleep, 200     ; Sleep only needed if executing lots of sends in a row or similar
}

我更喜欢使用函数(上面),因此代码更加模块化。

您可以使用热键的典型顺序执行来在没有它们的情况下执行相同的操作(如下所示):

~RButton::  ; These will execute sequential code below...
~MButton::

    PixelSearch, FoundX, FoundY, 258, 762, 258, 762, 0x000402, 0, Fast RGB
    If ErrorLevel
        Return

    Send, 2         ; Else if ErrorLevel was = 0, send "2"... shouldn't need brackets unless sending a special key
    ;Sleep, 200     ; Sleep only needed if executing lots of sends in a row or similar

Return

如果您想在MButtonRButton失败时重复发送“ 2”,则可以使用循环(类似于原始代码)。只要单击并按住一个或另一个按钮,该命令就会执行:

~RButton::MyFunction()  ; Remove ~ to make these calls block the clicks from passing through
~MButton::MyFunction()  ; otherwise, leave in place to block clicks and send "2" instead

MyFunction() {
    ; Check to see if button is still down each loop iteration...
    While GetKeyState("P", "RButton") || GetKeyState("P", "MButton") {
        PixelSearch, FoundX, FoundY, 258, 762, 258, 762, 0x000402, 0, Fast RGB
        If ErrorLevel {
            Sleep 10
            Continue
        }

        Send, 2         ; Else if ErrorLevel was = 0, send "2"... shouldn't need brackets unless sending a special key
        Sleep, 200      ; Sleep only needed if executing lots of sends in a row or similar

    } 
}

哇,你知道你在做什么
Marco Polo
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.