宏看起来无需“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
看起来你实际上并不需要循环(??)。
您是否只想触发RButton
或MButton
,并在每次点击时执行一次某件事?
~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
如果您想在MButton
或RButton
按下时重复发送“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
}
}