Sign in to follow this  
Followers 0
gamecity

Need a way to pause my script + all the hotkeys.

10 posts in this topic

I basically have a simple program. I have a bunch of hotkeys on the program.

For example

If I press "e" the program will call a function which will press a set of numbers like 5,6,7 or something like that.

What I would like is to be able to pause the program and the hotkeys. Maybe reassign them to different keys. When I'm about to chat, whenever I press the hotkeys, they will output a number instead of a letter. So I can't chat at all. The most common ones are "e" and "f".

So for simplicity's sake, I'll post a sample script on top of my head just like my program.

Global $Paused

Global $fkey = "{f}"

Global $ekey = "{e}"

HotKeySet("{PAUSE}", "TogglePause")

HotKeySet($fkey,"f_key_func")

HotKeySet($ekey,"e_key_func")

HotKeySet("{F10}","end")

Func f_key_func()

Send ("{1}")

EndFunc

Func e_key_func()

Send ("{2}")

EndFunc

Func end()

Exit

EndFunc

; first I tried this function but didn't work

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

; then I tried this function but didn't work also.

Func TogglePause()
        $fkey = "{<}"
        $ekey = "{>}"
EndFunc

So I just want to be able to pause the script and be able to chat or say a few words then go back to the program. It's a pain since I am using a program that is using full screen mode. It's really bothersome to alt-tab all the time just to restart the script.

Thank you in advance for the help or for the ideas.

Share this post


Link to post
Share on other sites



You'll need to add this flag to each function, say, if $fStop is true the function won't execute it's code and jump directly to the end of the function, otherwise, it won't work.

Share this post


Link to post
Share on other sites

Before the while loop in the pausing you have to declare:

HotKeySet("{PAUSE}")
HotKeySet($fkey)
HotKeySet($ekey)
HotKeySet("{F10}")oÝ÷ Ù8b³¥·¬zÛaz»¥zÆÚrKh¶¨®§j[¶Ø§ÈhÁëÞ­§íz»azZ(§*.Â)e«Þ¶^rV«zØ^¨{.r¬jëh×6HotKeySet("{PAUSE}", "TogglePause")
HotKeySet($fkey,"f_key_func")
HotKeySet($ekey,"e_key_func")
HotKeySet("{F10}","end")

Hope this helps and it will stop you from writing $fStop on every function to check to see if it is enabled


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

Before the while loop in the pausing you have to declare:

HotKeySet("{PAUSE}")
HotKeySet($fkey)
HotKeySet($ekey)
HotKeySet("{F10}")oÝ÷ Ù8b³¥·¬zÛaz»¥zÆÚrKh¶¨®§j[¶Ø§ÈhÁëÞ­§íz»azZ(§*.Â)e«Þ¶^rV«zØ^¨{.r¬jëh×6HotKeySet("{PAUSE}", "TogglePause")
HotKeySet($fkey,"f_key_func")
HotKeySet($ekey,"e_key_func")
HotKeySet("{F10}","end")

Hope this helps and it will stop you from writing $fStop on every function to check to see if it is enabled

I will try this. thanks.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You'll need to add this flag to each function, say, if $fStop is true the function won't execute it's code and jump directly to the end of the function, otherwise, it won't work.

I see what you are getting at also. I will have an else statement that says send "f" if fstop is true and "f" is pressed. But I'm pretty sure this will just call the function again since 'f' is a hotkey.

thanks.

Edited by gamecity

Share this post


Link to post
Share on other sites

All you need to do is look at HotKeySet help and viewing it will tell you how it function, although I rather have a Disable_HotKeySet or something other then setting the hotkey then resetting it to a blank one


0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E

Share this post


Link to post
Share on other sites

All you need to do is look at HotKeySet help and viewing it will tell you how it function, although I rather have a Disable_HotKeySet or something other then setting the hotkey then resetting it to a blank one

If you have a lot of hotkeys then I think some of the above suggestions are too complicated, though it's a matter of opinion.

I would sugget having only one function for all hotkeys and one function for the pause. Then you don't need to set or reset any hotkeys and life is much simpler.

This is what I suggest

HotKeySet("{F1}", "func1")
HotKeySet("{F2}", "func1")
HotKeySet("{F3}", "func1")
HotKeySet("{F4}", "func1")

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

Func TogglePause()
    $paused = Not $paused
EndFunc  ;==>TogglePause

Func func1()
    If $paused Then Return

    Switch @HotKeyPressed
        Case "{F1}"
            FuncF1()
        Case "{F2}"
            FuncF2()


           ;etc

    EndSwitch


EndFunc  ;==>func1


Func FuncF1()

EndFunc  ;==>FuncF1


Func FuncF2()

EndFunc  ;==>FuncF2

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks to everyone. The problem is solved. I did this basically. Which is a combination of the two posts.

HotKeySet("{e}", "func1")
HotKeySet("{f}", "func1")
HotKeySet("{PAUSE}", "TogglePause")

$paused = False


Call ("Start")

Func Start()
    While 1 = 1
;script here
    Wend
EndFunc


Func TogglePause()
    $paused = Not $paused
    HotKeySet("{e}", "func1")
    HotKeySet("{f}", "func1")
EndFunc ;==>TogglePause

Func func1()
    If $paused Then 
        HotKeySet("{e}")
        HotKeySet("{f}")
    EndIf

    Switch @HotKeyPressed
        Case "{e}"
            FuncF1()
        Case "{f}"
            FuncF2()
    EndSwitch


EndFunc ;==>func1

Func FuncF1()
    Send ("{7}")
EndFunc ;==>FuncF1

Func FuncF2()
    Send ("{8}")
EndFunc ;==>FuncF2

If the function just returns without resetting the hotkeys, I cannot type "e" or "f". The script doesn't output "e" or "f" in the chat. It basically doesn't do anything if the program is paused. I can press "e" or "f" and the program won't do anything. But if I reset the hotkeys, the script outputs "e" and "f" when paused but if it's not paused, the script outputs 7 or 8.

Thanks again everyone.

Share this post


Link to post
Share on other sites

Maybe the function should be

Func TogglePause()
     $paused = Not $paused
    if Not $paused then
       HotKeySet("{e}", "func1")
       HotKeySet("{f}", "func1")
    EndIf
 EndFunc;==>TogglePause

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Maybe the function should be

Func TogglePause()
     $paused = Not $paused
    if Not $paused then
       HotKeySet("{e}", "func1")
       HotKeySet("{f}", "func1")
    EndIf
 EndFunc;==>TogglePause

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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