Jump to content

how to deactivate a function


seres
 Share

Recommended Posts

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

Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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