Jump to content

Script doesn't Toggle between On and Off State


asidi
 Share

Recommended Posts

Hi all,

I created a script that is supposed to change the value of a command (enabledev) in an .ini file between 0 and 1 by pressing F10, but currently, it only changes the value from 1 to 0, but not the other way around. What did I do wrong here?

 

Here is the script:

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.


#requireadmin

; --------------------------------------------------
; Define variables, include files.
; --------------------------------------------------

#include <Misc.au3>
Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon
Opt("MouseCoordMode", 0)
Opt("SendKeyDelay", 0)
Opt("MouseClickDelay", 0)

$title = "toggle1"
$file = @ScriptDir & "\config.ini"

$toggle_off = 0

$toggle_on = 1
; --------------------------------------------------


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

; --------------------------------------------------
; Check if Script is already running
; --------------------------------------------------

If _Singleton($title, 1) = 0 Then
    Beep(135, 250)
    Exit
EndIf

; --------------------------------------------------
; Script is running - Beep!
; --------------------------------------------------

Beep(500, 250)

; ==================================================
; Main Script Loop
; ==================================================

While 1
    Sleep(100)
WEnd

Func _readToggle()
    $toggle_on = IniRead($file, "enabledev", "Active", 1)
EndFunc   ;==>_readToggle

Func _writeToggleOn()
    IniWrite($file, "enabledev", "Active", $toggle_on)
EndFunc   ;==>_writeToggleOn

Func _writeToggleOff()
    IniWrite($file, "enabledev", "Active", $toggle_off)
EndFunc   ;==>_writeToggleOff()

Func toggleSwitch()
    _readToggle()
    If $toggle_on = 1 Then
        _writeToggleOff()
        Beep(500, 125)
    Else
        _writeToggleOn()
        Beep(250, 125)
    EndIf
    Sleep(100)
    Send("{F12}")
EndFunc   ;==>toggleSwitch()

 

Link to comment
Share on other sites

#include <Misc.au3>

Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon
Opt("MouseCoordMode", 0)
Opt("SendKeyDelay", 0)
Opt("MouseClickDelay", 0)

;~ $title = "toggle1"
$file = @ScriptDir & "\config.ini"

Global $toggle = _readToggle()

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

If _Singleton($title, 1) = 0 Then
    Beep(135, 250)
    Exit
EndIf

Beep(500, 250)

While 1
    Sleep(100)
WEnd

Func _readToggle()
    Return IniRead($file, "enabledev", "Active", 1)
EndFunc   ;==>_readToggle

Func _writeToggle()
    IniWrite($file, "enabledev", "Active", $toggle)
EndFunc   ;==>_writeToggle

Func toggleSwitch()
    $toggle = 1 - $toggle
    If $toggle = 1 Then
        Beep(500, 125)
    Else
        Beep(250, 125)
    EndIf
    _writeToggle()
    Sleep(100)
    Send("{F12}")
EndFunc   ;==>toggleSwitch()

 

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