Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Stop Function With Hotkey


  • Please log in to reply
11 replies to this topic

#1 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 09 November 2008 - 04:39 AM

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, 09 November 2008 - 04:39 AM.








#2 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 09 November 2008 - 05:27 AM

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


#3 dbzfanatic

dbzfanatic

    functional psychopath!!

  • Active Members
  • PipPipPipPipPipPip
  • 1,090 posts

Posted 09 November 2008 - 05:43 AM

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


#4 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 09 November 2008 - 05:47 AM

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

Edited by Harusal, 09 November 2008 - 05:56 AM.


#5 dbzfanatic

dbzfanatic

    functional psychopath!!

  • Active Members
  • PipPipPipPipPipPip
  • 1,090 posts

Posted 09 November 2008 - 05:51 AM

You're welcome :mellow:.

#6 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 09 November 2008 - 05:57 AM

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

Edited by Harusal, 09 November 2008 - 06:11 AM.


#7 Demonic

Demonic

    Wayfarer

  • Active Members
  • Pip
  • 59 posts

Posted 09 November 2008 - 06:06 AM

Your while statement doesnt go into a function.

AutoIt         
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


#8 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 09 November 2008 - 06:22 AM

i did this:
Plain Text         
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, 09 November 2008 - 06:28 AM.


#9 system24

system24

    It has been a while.

  • Active Members
  • PipPipPipPipPipPip
  • 555 posts

Posted 09 November 2008 - 07:34 AM

Plain Text         
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

It's a question of mind over matter, if I don't mind, it doesn't matter.


#10 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 09 November 2008 - 10:38 PM

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

#11 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 10 November 2008 - 01:36 AM

it works fine but when i add a gui and i put the hotkeyset above the gui i get the error again.
Plain Text         
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, 10 November 2008 - 02:03 AM.


#12 Harusal

Harusal

    Seeker

  • Active Members
  • 21 posts

Posted 10 November 2008 - 06:40 PM

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

Plain Text         
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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users