Sign in to follow this  
Followers 0
seres

help one key combination for closing opening

5 posts in this topic

hello, how do i make a func to be closed or activated with the same key

here is my code

HotKeySet("^+!s", "new") ;opens new

HotKeySet("^+s", "new2") ;closes new

Func new()

run ("new")

EndFunc

Func new()

winclose ("new")

EndFunc

how do i make to open and close with the same hotkeys like if new is active then if i press the hotkeys again new will close

HotKeySet("^+!s", "new")

Func new()

run and close new

EndFunc

Share this post


Link to post
Share on other sites



Use a global variable to determine whether or not to run or close the window when the function is called:

Global $b_Run = True
HotKeySet("^+!s", "new")

While 1
    sleep(1000)
WEnd

Func new()
    If $b_Run = True Then
        run ("new")
        $b_Run = False
    Else
        winclose ("new")
        $b_Run = True
    Endif
EndFunc

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hi thanks for the help, it worked

but what does it mean $ , why do u add an "a_run" can it yust be "run", why at the end of the "if" goes "$Run = False", adn why do u have to make it global

i searched in the help file but i didnt understand it all

Edited by seres

Share this post


Link to post
Share on other sites

hi thanks for the help, it worked

but what does it mean $ , why do u add an "a_run" can it yust be "run", why at the end of the "if" goes "$Run = False", adn why do u have to make it global

i searched in the help file but i didnt understand it all

...but what does it mean $...

Look at the second paragraph here: http://www.autoitscript.com/autoit3/docs/i...g_variables.htm

...why do u add an "a_run"...

I didn't use a_Run anywhere. Perhaps you mean $b_Run? That is just the name of a boolean(True or False) variable that I created. If set to True, then the function will run a program. If set to False, the same function will close the window of the program. $b_ is an organized prefix that says that the variable contains a boolean value. If it contained a string I would have named it "$s_Run" instead of "$b_Run". So if you want, you could just call it "$Run", though this is bad coding practice since you now have no idea what datatype the variable contains.

...why at the end of the "if" goes "$Run = False"...

It sets it to false because it just ran the program. Now if you press the hotkey a second time, the "$b_Run" variable will be set to false, so the function will know that it already ran the program and that it should now close it. Upon closing the program it sets "$b_Run" to True so that when you press the hotkey later, the function knows to run the program and not close it.

...adn why do u have to make it global...

You must make it global scope so that the function in the script can see the variable. If you create the same variable with a local scope, any function that is in the script will not know of the existance of that variable which was declared in the main part of the script.

- The Kandie Man ;-)


"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

thanks man

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