Jump to content

Stop Function With Hotkey


Harusal
 Share

Recommended Posts

im trying to make so that i press a hotkey and it starts the function, but then when i press a different hotkey it will stop that same function. but i want to be still able to press the first hotkey and start the function again. if someone knows how to do this it will be a great help!

Edited by Harusal
Link to comment
Share on other sites

I think it would be something like this but i don't know how to do the function "Stop"

HotKeySet("{F4}", "ExitProg") 
HotKeySet("{F5}", "Start") 
HotKeySet("{F6}", "Stop") 

Func ExitProg()  
    Exit 0 ;;Exits the program
EndFunc

Func Start()
    While 1
    ;;Do Something
    Wend
    
    
    
    Func Stop()
;;Stop the Function "Start"
    Endfunc
Link to comment
Share on other sites

You could have a variable like

Func Start()
$var = 1
While $var = 1
;start code
WEnd
EndFunc

Func Stop()
$var = 0
EndFunc
Or for the same key to start/stop

Func Start()
$var = Not $var
While $var
;code func
WEnd
EndFunc
Link to comment
Share on other sites

Your while statement doesnt go into a function.

HotKeySet("{F4}", "ExitProg") 
HotKeySet("{F5}", "StartStop") 

$On = False

While 1
    While $On = True
        ;Your code you want toggled on and off
    WEnd
    Sleep(100)
WEnd

Func StartStop()
    If $On = False Then
        $On = True
    Else
        $On = False
    EndIf
EndFunc

Func ExitProg()
    Exit
EndFunc
Link to comment
Share on other sites

i did this:

HotKeySet("{F4}", "ExitProg") 
HotKeySet("{F5}", "StartStop") 
Func ExitProg()  
    Exit 0;;Exits the program
EndFunc

$On = False

While 1
    While $On = True
     ;;Do Code
    WEnd
    Sleep(100)
WEnd

Func StartStop()
    If $On = False Then
        $On = True
    Else
        $On = False
    EndIf
EndFunc

and i got this error

Posted Image

Posted Image

Edited by Harusal
Link to comment
Share on other sites

HotKeySet("{F4}", "ExitProg") 
HotKeySet("{F5}", "StartStop") 
Func ExitProg()  
    Exit 0;;Exits the program
EndFunc

Dim $On
$On = False

While 1
    While $On = True
    ;;Do Code
    WEnd
    Sleep(100)
WEnd

Func StartStop()
    If $On = False Then
        $On = True
    Else
        $On = False
    EndIf
EndFunc

[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]
Link to comment
Share on other sites

it works fine but when i add a gui and i put the hotkeyset above the gui i get the error again.

HotKeySet("!x", "ExitProg") 
HotKeySet("!s", "StartStop");Shift+s
GuiCreate("Program",218,68,332,219)
$label1=GuiCtrlCreateLabel("Alt+S",9,30,141,15)
$label2=GuiCtrlCreateLabel("Alt+X",115,30,105,15)
$label3=GuiCtrlCreateLabel("By Harusal",166,55,55,15)
GuiSetState()

While 1
$msg=GuiGetMsg()
If $msg=-3 Then Exit
Wend

Func ExitProg()  
    Exit 0;;Exits the program
EndFunc

Dim $On
$On = False

While 1
    While $On = True
  ;;Do Code
    WEnd
    Sleep(100)
WEnd

Func StartStop()
    If $On = False Then
        $On = True
    Else
        $On = False
    EndIf
EndFunc

Posted Image

Edited by Harusal
Link to comment
Share on other sites

it works fine but when i add a gui and i put the hotkeyset above the gui i get the error again.

HotKeySet("!x", "ExitProg") 
HotKeySet("!s", "StartStop");Shift+s
GuiCreate("Program",218,68,332,219)
$label1=GuiCtrlCreateLabel("Alt+S",9,30,141,15)
$label2=GuiCtrlCreateLabel("Alt+X",115,30,105,15)
$label3=GuiCtrlCreateLabel("By Harusal",166,55,55,15)
GuiSetState()

While 1
$msg=GuiGetMsg()
If $msg=-3 Then Exit
Wend

Func ExitProg()  
    Exit 0;;Exits the program
EndFunc

Dim $On
$On = False

While 1
    While $On = True
 ;;Do Code
    WEnd
    Sleep(100)
WEnd

Func StartStop()
    If $On = False Then
        $On = True
    Else
        $On = False
    EndIf
EndFunc

Posted Image

Nvm i got it working, thanks every 1!
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...