Jump to content
Sign in to follow this  
seres

how to deactivate a function

Recommended Posts

seres

hello, i have been wondering how to deactivate a function when called (with the same hotkey), i searched in the help file, but i found nothing

example:

CODE
HotKeySet("^1", "actideacti")

func actideacti()

endfunc

it calls the function, but how to deactivate it with the same hotkey

Share this post


Link to post
Share on other sites
Nahuel

I don't know what you mean by "deactivate it"... as in unset the hotkey? :P

HotKeySet("^1")

Or stop the function with the same hotkey?

Share this post


Link to post
Share on other sites
seres

yes its to stop the function with the same key

Share this post


Link to post
Share on other sites
Klaatu

Well, off the top of my head, I'd probably do something like this:

global $stopit = False
HotKeySet("^1", "actideacti")

func actideacti()
 HotKeySet("^1", "actideacti2")
 $stopit = False
 If $stopit then
  HotKeySet("^1", "actideacti")
  return
 endif
; do some stuff
 If $stopit then
  HotKeySet("^1", "actideacti")
  return
 endif
; do more stuff
 If $stopit then
  HotKeySet("^1", "actideacti")
  return
 endif
; etc
HotKeySet("^1", "actideacti")
endfunc

func actideacti2()
 $stopit = True
endfunc
Edited by Klaatu

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
Share on other sites
PsaltyDS

hello, i have been wondering how to deactivate a function when called (with the same hotkey), i searched in the help file, but i found nothing

it calls the function, but how to deactivate it with the same hotkey

Like this:

Global $fActive = False

HotKeySet("^1", "actideacti")

While 1
    While $fActive 
        _DoSomethingWhileActive()
    WEnd
    Sleep(20)
WEnd
    
func actideacti()
    $fActive = Not $fActive
endfunc

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
seres

Like this:

Global $fActive = False

HotKeySet("^1", "actideacti")

While 1
    While $fActive 
        _DoSomethingWhileActive()
    WEnd
    Sleep(20)
WEnd
    
func actideacti()
    $fActive = Not $fActive
endfunc

:P

it didnt worked for me cause it was repeating itself here is what i tried warning it will open a lot of note pads

Global $fActive = False

HotKeySet("^1", "actideacti")

While 1

While $fActive

run("notepad.exe")

WEnd

Sleep(20)

WEnd

func actideacti()

$fActive = Not $fActive

endfunc

Share this post


Link to post
Share on other sites
Achilles

HotKeySet('^a', 'Testing') 

While 1 
    Sleep(2000) 
WEnd 

Func Testing() 
    HotKeySet('^a') 
    ToolTip('Hot key has been disabled') 
    Sleep(3000) 
    ToolTIp('Exiting in 5 seconds') 
    Sleep(5000) 
        Exit
EndFunc

Edited by Piano_Man

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
seres

HotKeySet('^a', 'Testing') 

While 1 
    Sleep(2000) 
WEnd 

Func Testing() 
    HotKeySet('^a') 
    ToolTip('Hot key has been disabled') 
    Sleep(3000) 
    ToolTIp('Exiting in 5 seconds') 
    Sleep(5000) 
        Exit
EndFunc
i didnt mean to disable the hotkey, i mean to stop/disable the function, but thanks anyway

Share this post


Link to post
Share on other sites
seres

thanks the help guys, i tried them all but nothing, still thanks, the other way i knew to do it was to pick a diferent func that has the same keys, but i thought it will be better to yust deactivate it, or maybe i didnt find the way to stop it, thanks anyway.

Share this post


Link to post
Share on other sites
PsaltyDS

thanks the help guys, i tried them all but nothing, still thanks, the other way i knew to do it was to pick a diferent func that has the same keys, but i thought it will be better to yust deactivate it, or maybe i didnt find the way to stop it, thanks anyway.

You are still being absurdly vague, and haven't posted any code to explain what you want.

What does your "Function" do when it is "activated"? Exactly what does it mean to "deactivate" your function? What does "a diferent func that has the same keys" mean? What does your script do while this function is "deactivated"?

This has become another useless topic because it has gone on way too long without a clear statement of what is already done, and exactly what needs to be done.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
MuffettsMan

on the same topic (i think) is there a clean way to enable / disable hotkeys? as in you click an option and then using hotkeys to start a function no longer works... click it again then hotkey use is enabled...

snipits of my remidial logic / attempts:

HotKeySet("+!e", "EnableUser") ;Shift-Alt-e

$Togglekeys = TrayCreateItem("Disable Hotkeys")
TrayItemSetOnEvent(-1,"TogleHotkeysEvent")


Func TogleHotkeysEvent()
    if $HotKeyToggle == 1 then
        $HotKeyToggle = 0
        FileWrite($logfile, Timestamp() & "CMS Auto: HotKey Toggle - Notice: HotKey Functionality has been turned OFF." & @CRLF)
    ;MsgBox(4096, "Hotkey Toggle:", "HotKey Functionality has been turned OFF.", 5)
        TrayItemDelete($Togglekeys)
        $Togglekeys = TrayCreateItem("Enable Hotkeys")
        TrayItemSetOnEvent(-1,"TogleHotkeysEvent")
        TrayTip("CMS Auto: HotKey Toggle", "Notice: HotKey Functionality has been turned OFF.", 5, 1)
    Else
        $HotKeyToggle = 1
    ;MsgBox(4096, "Hotkey Toggle:", "HotKey Functionality has been turned ON.", 5)
        TrayItemDelete($Togglekeys)
        $Togglekeys = TrayCreateItem("Disable Hotkeys")
        TrayItemSetOnEvent(-1,"TogleHotkeysEvent")
        FileWrite($logfile, Timestamp() & "CMS Auto: HotKey Toggle - Notice: HotKey Functionality has been turned ON." & @CRLF)
        TrayTip("CMS Auto: HotKey Toggle", "Notice: HotKey Functionality has been turned ON.", 5, 1)
    EndIf
EndFunc

Func EnableUser()
    if $HotKeyToggle == 1 Then
        $MsgBoxVal = MsgBox(4, $title, "You are about to do stuff: " & $UID & " hotkeys are enabled....")
    ; etc etc etc....
    Else;Hotkeys must be disabled so do nothing....
        return
    EndIf
EndFunc
; ***********

basicly is setting a flag the best way to toggle?


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites
PsaltyDS

on the same topic (i think) is there a clean way to enable / disable hotkeys? as in you click an option and then using hotkeys to start a function no longer works... click it again then hotkey use is enabled...

snipits of my remidial logic / attempts:

basicly is setting a flag the best way to toggle?

It's simpler than you think:

Opt("TrayOnEventMode", 1)
Opt("TrayAutoPause", 0)

Global $fHotKeys = False
Global $Togglekeys = TrayCreateItem("Hotkeys Enabled", -1, 1) ; Enable MenuRadioItem
TrayItemSetOnEvent(-1, "TogleHotkeysEvent")

While 1
    Sleep(20)
WEnd

Func TogleHotkeysEvent()
    $fHotKeys = Not $fHotKeys
    If $fHotKeys Then
        TrayItemSetState($Togglekeys, 1) ; 1 = $TRAY_CHECKED
        HotKeySet("+!e", "EnableUser") ; Shift-Alt-e
    Else
        TrayItemSetState($Togglekeys, 4) ; 4 = $TRAY_UNCHECKED
        HotKeySet("+!e")
    EndIf
EndFunc   ;==>TogleHotkeysEvent

Func EnableUser()
    MsgBox(64, "Debug", "HotKey detected, EnableUser() running...")
EndFunc   ;==>EnableUser

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
MuffettsMan

It's simpler than you think:

;)

nice nice niiiice now if i could simply quit doing things the hard way :P I guess limited knowledge = longer code


Don't let that status fool you, I am no advanced memeber!

Share this post


Link to post
Share on other sites
MuffettsMan

that also keeps my tray list from constantly getting reordered! <3 <3


Don't let that status fool you, I am no advanced memeber!

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  

×