Jump to content

Recommended Posts

Posted

To prevent multiple instances of the same script I use "_Singleton" function:

#include <Misc.au3>


If _Singleton("ScriptID", 1) = 0 Then
    Exit
EndIf

HotKeySet("{F2}", "_test")

While 1
    Sleep(100)
WEnd

Func _test()
    MsgBox(64, "Title", "Content")
EndFunc

However, if I double-click this script, then change "Content" to "New content" and then double-click again - it will not be updated. It will be just "Content". How to fix it?

Also, another question: Is there more elegant way to prevent script from immediately exiting? Currently I use "while" for it.

Posted

your first script does not end. The hotkey is allocated to the first script and work fine.

The hotkeyset of the second script fails due to hotkey already defined.

App: Au3toCmd              UDF: _SingleScript()                             

Posted

@Exit I understand. But how to fix it? I came here from AutoHotkey world, and it was quite easy there: just add "#SingleInstance, Force" line in the top of the script and that's all.

Posted (edited)

@john_2019 Just use my UDF "_SingleScript.au3

Here a sample code

#include "_SingleScript.au3"  ; http://www.autoitscript.com/forum/index.php?showtopic=178681

_SingleScript()
HotKeySet("{F2}", "_test")
MsgBox(64 + 262144, Default, "Press OK and then F2", 0)
While 1
    Sleep(1000)
WEnd

Func _test()
    MsgBox(64+262144, Default, "Test 1",0)     ;  change text here to see difference
    Exit
EndFunc   ;==>_test

 

The _SingleScript.au3   code can be found here

 

Edited by Exit
point to new #include location

App: Au3toCmd              UDF: _SingleScript()                             

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...