Jump to content

Simple toggle function not turning off


WhaleJesus
 Share

Recommended Posts

HotKeySet("+m", "Bridge")

$bridge = False

Func Bridge()
    $bridge = Not $bridge
    If $bridge = True Then
        Send("{CTRLDOWN}")
        Send("{s down}")
    Else
        Send("{s up}")
        Send("{CTRLUP}")
    EndIf
EndFunc

While 1
    If $bridge = True Then
        Sleep(2000)
        MouseClick("right")
    EndIf
WEnd

When i press "SHIFT + M" the keypresses and mouseclicks are being executed, but when i press "SHIFT + M" again to turn it off, it won't stop. any ideas what is going wrong here?

Link to comment
Share on other sites

works for me. Maybe there are multiple instances of the script running (as you don't have a kill switch). Did you kill the running instance via task manager after every test?

BTW: You can "debug" it with MsgBox like so.
 

#include <Constants.au3>

MsgBox($MB_SYSTEMMODAL, "Bridge Tool", "Start")

HotKeySet("+m", "Bridge")

$bridge = False

Func Bridge()
    $bridge = Not $bridge
    If $bridge = True Then
        Send("{CTRLDOWN}")
        Send("{s down}")
        MsgBox($MB_SYSTEMMODAL, "Bridge Tool", "bridge = True")
    Else
        Send("{s up}")
        Send("{CTRLUP}")
        MsgBox($MB_SYSTEMMODAL, "Bridge Tool", "bridge = False")
    EndIf
EndFunc

While 1
    If $bridge = True Then
        Sleep(2000)
        MouseClick("right")
        MsgBox($MB_SYSTEMMODAL, "Bridge Tool", "in while loop ...")
    EndIf
WEnd


Br
Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

5 minutes ago, Sunblood said:

CTRL and S are still being held down by the script, so when you press SHIFT+M again you're really pressing CTRL+SHIFT+M. Try a hotkey with no modifiers to enable/disable instead.

you are right!  I modified the script for my quick test :-)

Br
Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...