0

标题说明了一切。我正在创建一个可以无限期地为我键入键的应用程序,但我想在热键按下时停止它,或者当我输入“.stop”之类的内容时,但我不知道如何实现。我已经尝试过了,所以当我单击 CMD + Y 时,它会使变量停止为真,并且在发送垃圾邮件时,它会检查变量是否为真,如果是,则停止,但它不起作用。

代码:

hs.alert.show("Spam")
                local commands = split(command, ",")
                local args = split(command, " ")
                local todo = {}
                if #commands ~= 1 then
                    -- Get all the commands
                    commands[1] = commands[1]:sub(11, -1)
                    for _,cmd in pairs(commands) do
                        print(cmd)
                    end
                    hs.eventtap.keyStrokes("/", hs.application.get(botinstance:pid()))
                    hs.timer.usleep(90000)
                    hs.eventtap.keyStrokes("/c system", hs.application.get(botinstance:pid()))
                    hs.timer.usleep(90000)
                    hs.eventtap.keyStroke({}, "return", 100000, hs.application.get(botinstance:pid()))
                    hs.timer.usleep(90000)
                    local yi = 0
                    while yi <= tonumber(args[#args]) do
                        for _, cmd in pairs(commands) do
                            if halted == true then
                                print("HALTED")
                                break
                            else
                                hs.eventtap.keyStrokes("/", hs.application.get(botinstance:pid()))
                                hs.timer.usleep(90000)
                                hs.eventtap.keyStrokes(cmd, hs.application.get(botinstance:pid()))
                                hs.timer.usleep(90000)
                                hs.eventtap.keyStroke({}, "return", 100000, hs.application.get(botinstance:pid()))
                                hs.timer.usleep(90000)
                                yi = yi + 1
                            end
                        end
                    end
                else
                    local reason = ""
                    hs.eventtap.keyStrokes("/", hs.application.get(botinstance:pid()))
                    hs.timer.usleep(15000)
                    hs.eventtap.keyStrokes("/c system", hs.application.get(botinstance:pid()))
                    hs.timer.usleep(15000)
                    hs.eventtap.keyStroke({}, "return", 100000, hs.application.get(botinstance:pid()))
                    hs.timer.usleep(15000)
                    for _, v in pairs(args) do
                        if v == "spam" or v == args[#args] or v == ".bot" then
                        else
                            reason = reason.." "..v
                        end
                    end
                    print(reason:sub(2, -1))
                    reasons = reason:sub(2, -1)
                    local yi = 0
                    while yi <= tonumber(args[#args]) do
                        if halted == true then
                            print("HALTED")
                            break
                        else
                            hs.eventtap.keyStrokes("/", hs.application.get(botinstance:pid()))
                            hs.timer.usleep(15000)
                            hs.eventtap.keyStrokes(reasons, hs.application.get(botinstance:pid()))
                            hs.timer.usleep(15000)
                            hs.eventtap.keyStroke({}, "return", 100000, hs.application.get(botinstance:pid()))
                            hs.timer.usleep(15000)
                            yi = yi + 1
                        end
                    end
                end
4

0 回答 0