Jump to content

Hotkey Start and Stop?


RadioBoy
 Share

Recommended Posts

I have a question. How would you make a macro script in which when you hit a hotkey, such as F4, and it begins spamming text like "HI" over and over in a continuous loop until you hit another hotkey such as F6? I know it's a newbie question... but I tried searching already and came up with nothing. Thank you for even bothering to read this topic because I can't imagine the frustration you have pros have to deal with against newbies like me everyday.

Link to comment
Share on other sites

HotKeySet('{F3}', 'Spam')
HotKeySet('{F4}', 'Stop')
HotKey('{ESC}, 'Exit')

Func Spam()
Do
Send('SPAM' & '{ENTER}')
Until ?
EndFunc

Func Stop()
ExitLoop
EndFunc

Func Exit()
Exit
EndFunc

So far this is my horrible noob script. -.-

Edited by RadioBoy
Link to comment
Share on other sites

I assume you were trying to lead me to your post in this topic. Well, I read up on it, so I decided to try rewriting the script based off of the script you posted and off of my own assumtions.

Would this work?

$spam = HotKeySet('{F3}', 'Spam')
$exit = HotKeySet('{ESC}', 'Close')

Func Spam()
While 1
$msg = GUIGetMsg()
Select  
Case $msg = $spam
        Do
            Send('SPAM' & '{ENTER}')
            $msg = GUIGetMsg()
        Until $msg = $stop
        MsgBox(0,0,0)
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
EndSelect
WEnd
EndFunc

Func Close()
Exit
EndFunc
Edited by RadioBoy
Link to comment
Share on other sites

Global $paused
HotKeySet( "{PAUSE}", "TogglePause")

; Put any scripting here
; when you hit the pause key it will stop everthing your script is doing till you hit pause again

Func TogglePause()
    $paused = Not $paused
    While $paused
        Sleep(100)
        ToolTip('PROGRAM IS PAUSED', 500, 100);Not nessesary but i like the tool tip
    WEnd
EndFunc

-----------Current Programming Language Status:Beginner: J#, Ruby Intermediate: Autoit, Java, C#, C++Advanced: Basic, Visual Basic, Fortran

Link to comment
Share on other sites

Global $paused
HotKeySet( "{PAUSE}", "TogglePause")

; Put any scripting here
; when you hit the pause key it will stop everthing your script is doing till you hit pause again

Func TogglePause()
    $paused = Not $paused
    While $paused
        Sleep(100)
        ToolTip('PROGRAM IS PAUSED', 500, 100);Not nessesary but i like the tool tip
    WEnd
EndFunc
How does it understand what $paused is?
Random
Link to comment
Share on other sites

How does it understand what $paused is?

It doesn't. $paused is used as a boolean variable in this script, meaning it can have true or false for a value. The statement $pause = not $pause means that the state is inverted (toggled). If it was true before, it is false after, and v.v.. Then the script does something if $pause is true (it pauses, obviously :whistle:).

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

A more correct / readable way would be like this

Global $paused = FALSE
HotKeySet( "{PAUSE}", "TogglePause")

; Put any scripting here
; when you hit the pause key it will stop everthing your script is doing till you hit pause again

Func TogglePause()
    $paused = Not $paused
    While $paused
        Sleep(100)
        ToolTip('PROGRAM IS PAUSED', 500, 100);Not nessesary but i like the tool tip
    WEnd
EndFunc

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

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...