caiolps Posted April 7, 2018 Share Posted April 7, 2018 Hello. I'm newbie using Autoit, so, I came here to ask for help with my script. I'm trying to make a toggle on/off by clicking in a image that I'm using as button. Here is my script: expandcollapse popupFunc _MAIN() $HiddenGUI = GUICreate("INVISIBLEParentWindow") $MainX = IniRead(@WindowsDir & "\GuardianSettings.ini", "GuardianPosition", "X", "") $MainY = IniRead(@WindowsDir & "\GuardianSettings.ini", "GuardianPosition", "Y", "") local $bmp = @TempDir & "\GuardianFiles\HUD\bg.bmp" $GUI = GUICreate("Guardian", 170, 85, $MainX ,$MainY , $WS_POPUP, $WS_EX_TOPMOST, $HiddenGUI) GUISetBkColor (0x000000, $GUI) $Pic1 = GUICtrlCreatePic($bmp, 0, 0, 170, 85) ; Img GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $GUI) $Pic1 = @TempDir & "\GuardianFiles\Icons\c2.png" $a1 = _GUICtrlPic_Create($Pic1 , 11, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic2 = @TempDir & "\GuardianFiles\Icons\c3.png" $a2 = _GUICtrlPic_Create($Pic2 , 49, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic3 = @TempDir & "\GuardianFiles\Icons\d2.png" $a3 = _GUICtrlPic_Create($Pic3 , 87, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic4 = @TempDir & "\GuardianFiles\Icons\f1.png" $f1 = _GUICtrlPic_Create($Pic4 , 125, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic5 = @TempDir & "\GuardianFiles\Buttons\minimize.png" $min = _GUICtrlPic_Create($Pic5 , 98, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic6 = @TempDir & "\GuardianFiles\Buttons\close.png" $close = _GUICtrlPic_Create($Pic6 , 119, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic7 = @TempDir & "\GuardianFiles\Buttons\help.png" $help = _GUICtrlPic_Create($Pic7 , 77, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic8 = @TempDir & "\GuardianFiles\Buttons\info.png" $info = _GUICtrlPic_Create($Pic8 , 56, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic9 = @TempDir & "\GuardianFiles\Buttons\settings.png" $settings = _GUICtrlPic_Create($Pic9 , 35, 61, 16, 16) GUICtrlSetCursor (-1, 0) GUISetState(@SW_SHOW, $GUI) WinSetTrans($GUI, "", IniRead(@WindowsDir & "\GuardianSettings.ini", "TransparencySettings", "Visibility", "")) $WM_SYSCommand1 = 274 $SC_MonitorPower = 61808 $Power_On = -1 $Power_Off = 2 $HWND = WinGetHandle("classname=Progman") While 1 Global $UnPaused $UnPaused = 0 $Traymsg = TrayGetMsg () If $Traymsg = $TrayItem Then _Settings() If $Traymsg = $TrayItemExit Then _Exit() If $Traymsg = $TrayItemHide Then _Hide() If $Traymsg = $TrayItemShow Then _Show() $msg = GUIGetMsg() If $msg = $a1 Then Winactivate("notepad") Send("a") ElseIf $msg = $a2 Then Winactivate("notepad") Send("b") ElseIf $msg = $a3 Then Winactivate("notepad") While $UnPaused = 0 ToolTip("Sending...",0,0) Send("c") Sleep(100) WEnd ElseIf $msg = $f1 Then Winactivate("notepad") Send("d") ElseIf $msg = $min Then GUISetState(@SW_HIDE, $GUI) TrayTip("Guardian", "Guardian is still running. You may click on tray icon to show again.", 0, $TIP_ICONASTERISK) ElseIf $msg = $close Then Exit I want that when I click on ElseIf $msg = $a3 Then it starts to send the letter c, but when I click again, it stops to send. I hope that anyone here help me. Thanks in advance. Link to comment Share on other sites More sharing options...
Subz Posted April 7, 2018 Share Posted April 7, 2018 Untested but try something like: expandcollapse popupFunc _MAIN() Global $UnPaused = 1 $HiddenGUI = GUICreate("INVISIBLEParentWindow") $MainX = IniRead(@WindowsDir & "\GuardianSettings.ini", "GuardianPosition", "X", "") $MainY = IniRead(@WindowsDir & "\GuardianSettings.ini", "GuardianPosition", "Y", "") local $bmp = @TempDir & "\GuardianFiles\HUD\bg.bmp" $GUI = GUICreate("Guardian", 170, 85, $MainX ,$MainY , $WS_POPUP, $WS_EX_TOPMOST, $HiddenGUI) GUISetBkColor (0x000000, $GUI) $Pic1 = GUICtrlCreatePic($bmp, 0, 0, 170, 85) ; Img GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW, $GUI) $Pic1 = @TempDir & "\GuardianFiles\Icons\c2.png" $a1 = _GUICtrlPic_Create($Pic1 , 11, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic2 = @TempDir & "\GuardianFiles\Icons\c3.png" $a2 = _GUICtrlPic_Create($Pic2 , 49, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic3 = @TempDir & "\GuardianFiles\Icons\d2.png" $a3 = _GUICtrlPic_Create($Pic3 , 87, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic4 = @TempDir & "\GuardianFiles\Icons\f1.png" $f1 = _GUICtrlPic_Create($Pic4 , 125, 23, 34, 34) GUICtrlSetCursor (-1, 0) $Pic5 = @TempDir & "\GuardianFiles\Buttons\minimize.png" $min = _GUICtrlPic_Create($Pic5 , 98, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic6 = @TempDir & "\GuardianFiles\Buttons\close.png" $close = _GUICtrlPic_Create($Pic6 , 119, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic7 = @TempDir & "\GuardianFiles\Buttons\help.png" $help = _GUICtrlPic_Create($Pic7 , 77, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic8 = @TempDir & "\GuardianFiles\Buttons\info.png" $info = _GUICtrlPic_Create($Pic8 , 56, 61, 16, 16) GUICtrlSetCursor (-1, 0) $Pic9 = @TempDir & "\GuardianFiles\Buttons\settings.png" $settings = _GUICtrlPic_Create($Pic9 , 35, 61, 16, 16) GUICtrlSetCursor (-1, 0) GUISetState(@SW_SHOW, $GUI) WinSetTrans($GUI, "", IniRead(@WindowsDir & "\GuardianSettings.ini", "TransparencySettings", "Visibility", "")) $WM_SYSCommand1 = 274 $SC_MonitorPower = 61808 $Power_On = -1 $Power_Off = 2 $HWND = WinGetHandle("classname=Progman") AdlibRegister("_Toggle") While 1 $Traymsg = TrayGetMsg () Switch $Traymsg Case $TrayItem _Settings() Case $TrayItemExit _Exit() Case $TrayItemHide _Hide() Case $TrayItemShow _Show() EndSwitch $msg = GUIGetMsg() Switch $msg Case $a1 Winactivate("notepad") Send("a") Case $a2 Winactivate("notepad") Send("b") Case $a3 If $UnPaused = 0 Then $UnPaused = 1 ElseIf $UnPaused = 1 Then $UnPaused = 0 EndIf Case $f1 Winactivate("notepad") Send("d") Case $min GUISetState(@SW_HIDE, $GUI) TrayTip("Guardian", "Guardian is still running. You may click on tray icon to show again.", 0, $TIP_ICONASTERISK) Case $close Exit EndSwitch WEnd AdlibUnRegister("_Toggle") Func _Toggle() If $UnPaused = 0 Then ToolTip("Sending...",0,0) Winactivate("notepad") Send("c") EndIf EndFunc Link to comment Share on other sites More sharing options...
Malkey Posted April 7, 2018 Share Posted April 7, 2018 Your example of post #1 was too far away from working with 17 errors and 8 warnings. It's not worth the effort to debug. This working example is a modified example from the GUICtrlCreatePic() function in the AutoIt help file. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Example() Func Example() Local $sCtrlText, $bToggle = True Local $iPID = Run("notepad.exe") GUICreate("My GUI picture", 350, 300, -1, -1, $WS_SIZEBOX + $WS_SYSMENU) GUISetBkColor(0xE0FFFF) Local $sImageFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\mslogo.jpg" Local $idPic = GUICtrlCreatePic($sImageFile, 50, 50, 200, 50) GUICtrlSetTip(-1, "Image On") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idPic $bToggle = Not $bToggle GUICtrlSetTip($idPic, ($bToggle ? "Image On" : "Image Off")) EndSwitch If $bToggle Then $sCtrlText = ControlGetText("[CLASS:Notepad]", "", "Edit1") If Mod(StringLen($sCtrlText), 22) = 0 Then $sCtrlText &= @CRLF ControlSetText("[CLASS:Notepad]", "", "Edit1", $sCtrlText & "c") Sleep(100) EndIf WEnd GUIDelete() ProcessClose($iPID) EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now