Sign in to follow this  
Followers 0

Stop Function With Hotkey

12 posts in this topic

Posted (edited)

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

Share this post


Link to post
Share on other sites



Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (edited)

I didn't think of that! Thanks So Much!! :mellow:

Edited by Harusal

Share this post


Link to post
Share on other sites

Posted

You're welcome :mellow:.

Share this post


Link to post
Share on other sites

Posted (edited)

It's doing the code but it won't end when i press F6

Edited by Harusal

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

i got it working, thanks so much for all of your help! =)

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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!

Share this post


Link to post
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
Sign in to follow this  
Followers 0