Jump to content

Checkbox and loop


Recommended Posts

 

I have a problem, I want the function :send key in  loop to be activated when the checkbox is selected and when the check box is turned off, the function turns off. I tried and only one checkbox works after selecting the second checkbox is flashing and cant be unchecked.

I have looked through the entire forum and there is no such topic anywhere

code

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include<Date.au3>
#include <DateTimeConstants.au3>
#include <InetConstants.au3>
#include <WinAPIFiles.au3>
#RequireAdmin
Global $Paused
HotKeySet("{f9}", "TogglePause")

 Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("test)", 269, 165, 228, 373)
Local $Checkbox1 = GUICtrlCreateCheckbox("", 240, 24, 17, 17)
GUICtrlSetOnEvent($Checkbox1,"test1")
 GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
 $Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 240, 48, 17, 17)
 GUICtrlSetOnEvent($Checkbox2,"test2")
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_SHOW)
global $start1 = 0
Lglobal $start2=0
While 1
    if GUICtrlRead($Checkbox2)= 1 Then
            
          Send( "{f1}" )

        EndIf

            if GUICtrlRead($Checkbox1)= 1 Then
            Send( "{f2}" )

EndIf




WEnd


Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused = SCRIPT IS NOT RUNNING = you wont get another message if you dont unpause it"',0,0)
    WEnd
    ToolTip("")
EndFunc




Func test1()


        $start1 =1


    EndFunc
Func test2()

$start2=1

EndFunc

Func _Exit()
    Exit
    EndFunc

 

Link to comment
Share on other sites

Works fine for me.  I can check and uncheck both checkboxes without any issues.  You did misspell the line at "Global start2 = 0". 

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

    AutoIt Version: 3.3.14.5
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <InetConstants.au3>
#include <WinAPIFiles.au3>
#RequireAdmin
Global $Paused
HotKeySet("{f9}", "TogglePause")

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("test)", 269, 165, 228, 373)
Local $Checkbox1 = GUICtrlCreateCheckbox("", 240, 24, 17, 17)
GUICtrlSetOnEvent($Checkbox1, "test1")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 240, 48, 17, 17)
GUICtrlSetOnEvent($Checkbox2, "test2")
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_SHOW)
Global $start1 = 0
Global $start2 = 0
While 1
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
        Send("{f1}")
        Msgbox(0,"", "2nd checkbox is checked.", 1)
    EndIf

    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        Send("{f2}")
        Msgbox(0,"", "1st checkbox is checked.", 1)
    EndIf
WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused = SCRIPT IS NOT RUNNING = you wont get another message if you dont unpause it"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func test1()
    $start1 = 1
EndFunc   ;==>test1

Func test2()
    $start2 = 1
EndFunc   ;==>test2

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

Edited by LisHawj
Link to comment
Share on other sites

4 hours ago, LisHawj said:

Works fine for me.  I can check and uncheck both checkboxes without any issues.  You did misspell the line at "Global start2 = 0". 

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

    AutoIt Version: 3.3.14.5
    Author:         myName

    Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <DateTimeConstants.au3>
#include <InetConstants.au3>
#include <WinAPIFiles.au3>
#RequireAdmin
Global $Paused
HotKeySet("{f9}", "TogglePause")

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("test)", 269, 165, 228, 373)
Local $Checkbox1 = GUICtrlCreateCheckbox("", 240, 24, 17, 17)
GUICtrlSetOnEvent($Checkbox1, "test1")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 240, 48, 17, 17)
GUICtrlSetOnEvent($Checkbox2, "test2")
#EndRegion ### END Koda GUI section ###
GUISetState(@SW_SHOW)
Global $start1 = 0
Global $start2 = 0
While 1
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
        Send("{f1}")
        Msgbox(0,"", "2nd checkbox is checked.", 1)
    EndIf

    If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
        Send("{f2}")
        Msgbox(0,"", "1st checkbox is checked.", 1)
    EndIf
WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused = SCRIPT IS NOT RUNNING = you wont get another message if you dont unpause it"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func test1()
    $start1 = 1
EndFunc   ;==>test1

Func test2()
    $start2 = 1
EndFunc   ;==>test2

Func _Exit()
    Exit
EndFunc   ;==>_Exit

 

thank you

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