Kraviks Posted August 31, 2014 Share Posted August 31, 2014 I'm trying to make it where if I check a checkbox, Macro 1 will run, if I turn that macro off and check another box...the same hotkey will run a different macro. However, I can get the first to work, but when I uncheck the first box and check the second box... it does nothing. But if I check the second box first...it works and when I switch to the first switch, it does nothing. Also After activating a checkbox, the Close and the red X on the top right of the window won't close the program. It will work if I don't select a checkbox, but otherwise...no go. Have to force close from SciTE Any help will be great. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <misc.au3> Local $hDLL = DllOpen("user32.dll") Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Testing", 300, 160) ; Create a checkbox control. Local $idCheckbox1 = GUICtrlCreateCheckbox("Hold Down Right Mouse", 10, 10, 125, 25) Local $idCheckbox2 = GUICtrlCreateCheckbox("Hold Down Left Mouse", 10, 30, 125, 25) Local $idClose = GUICtrlCreateButton("Close", 210, 130, 85, 25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop Case $idCheckbox1 If GUICtrlRead($idCheckbox2) = $GUI_CHECKED Then GUICtrlSetState($idCheckbox2, $GUI_UNCHECKED) EndIf While 1 If _IsChecked($idCheckbox1) Then If _IsPressed("5A") Then MouseDown("Right") Sleep(500) MouseUp("Right") Else EndIf Else EndIf WEnd Case $idCheckbox2 If GUICtrlRead($idCheckbox1) = $GUI_CHECKED Then GUICtrlSetState($idCheckbox1, $GUI_UNCHECKED) EndIf While 1 If _IsChecked($idCheckbox1) Then If _IsPressed("5A") Then MouseDown("Left") Sleep(500) MouseUp("Left") Else EndIf Else EndIf WEnd EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Link to comment Share on other sites More sharing options...
mikell Posted August 31, 2014 Share Posted August 31, 2014 You have got no way to quit the while loops ... Link to comment Share on other sites More sharing options...
Kraviks Posted August 31, 2014 Author Share Posted August 31, 2014 (edited) So, can you give me a solution? I'm still a noob to this and learning. How do I fix the problem? I don't want to close the program by unchecking the box...only want to activate a macro with checkboxes and switch between them. Edited August 31, 2014 by Kraviks Link to comment Share on other sites More sharing options...
Kraviks Posted August 31, 2014 Author Share Posted August 31, 2014 I'm staying on this page and refreashing as I'm looking for help as soon as possible. OCD has kicked in on this so it's bugging the heck out of me. Link to comment Share on other sites More sharing options...
Kraviks Posted August 31, 2014 Author Share Posted August 31, 2014 I really need help with this. Link to comment Share on other sites More sharing options...
mikell Posted August 31, 2014 Share Posted August 31, 2014 (edited) Ok First, use radio buttons to get rid of the check/uncheck problem 2nd, if you need a hotkey then use Hotkeyset 3rd, the helpfile is your best friend Sample script : #include <GUIConstantsEx.au3> HotKeySet ( "z" , "_Run") $hGUI = GUICreate("Testing", 300, 160) $idCheckbox1 = GUICtrlCreateRadio("Hold Down Right Mouse", 10, 10, 125, 25) $idCheckbox2 = GUICtrlCreateRadio("Hold Down Left Mouse", 10, 30, 125, 25) $idClose = GUICtrlCreateButton("Close", 210, 130, 85, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop EndSwitch WEnd Func _Run() If _IsChecked($idCheckbox1) Then Msgbox(0,"", "text 1") If _IsChecked($idCheckbox2) Then Msgbox(0,"", "text 2") EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Edit My bad, I forgot : If you bump too fast , this will be considered as flood and your topic will be locked Edited August 31, 2014 by mikell Link to comment Share on other sites More sharing options...
Kraviks Posted September 1, 2014 Author Share Posted September 1, 2014 Ok, I used your script...but however, it doesn't use macros. Also, I was using "IF _IsPressed("5A") Then" b/c I want it where it repeats the macro until I release the key. Not only does this do what it did before, I still can't close the program with the X or Close button. Load my script and run it. expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet ( "z" , "_Run") $hGUI = GUICreate("Testing", 300, 160) $idCheckbox1 = GUICtrlCreateRadio("Hold Down Right Mouse", 10, 10, 125, 25) $idCheckbox2 = GUICtrlCreateRadio("Hold Down Left Mouse", 10, 30, 125, 25) $idClose = GUICtrlCreateButton("Close", 210, 130, 85, 25) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop EndSwitch WEnd Func _Run() If _IsChecked($idCheckbox1) Then While 1 If _IsPressed("5A") Then MouseDown("Right") Sleep(500) MouseUp("Right") WEnd EndIf If _IsChecked($idCheckbox2) Then While 1 If _IsPressed("5A") Then MouseDown("Left") Sleep(500) MouseUp("Left") WEnd EndIf EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Link to comment Share on other sites More sharing options...
mikell Posted September 1, 2014 Share Posted September 1, 2014 Indeed using both HotkeySet and _IsPressed for the same key is not a good idea And you cannot exit the program because there is no condition in the While loops allowing to quit them Try this expandcollapse popup#include <GUIConstantsEx.au3> #include <Misc.au3> $hGUI = GUICreate("Testing", 300, 160) $idCheckbox1 = GUICtrlCreateRadio("Hold Down Right Mouse", 10, 10, 125, 25) $idCheckbox2 = GUICtrlCreateRadio("Hold Down Left Mouse", 10, 30, 125, 25) $idClose = GUICtrlCreateButton("Close", 210, 130, 85, 25) GUISetState() While 1 _Run() Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idClose ExitLoop EndSwitch WEnd Func _Run() If _IsPressed("5A") Then If _IsChecked($idCheckbox1) Then Do MouseDown("Right") Sleep(500) MouseUp("Right") Sleep(500) Until not _IsPressed("5A") EndIf If _IsChecked($idCheckbox2) Then Do MouseDown("Left") Sleep(500) MouseUp("Left") Sleep(500) Until not _IsPressed("5A") EndIf EndIf EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked BTW these macros are for which kind of work ? Link to comment Share on other sites More sharing options...
Kraviks Posted September 1, 2014 Author Share Posted September 1, 2014 I'm using making a macro for DC Universe Online to learn how to code Autoit. I've just started but I think I'm making progress. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 1, 2014 Moderators Share Posted September 1, 2014 Kraviks, a macro for DC Universe OnlineUnfortunately you appear to have missed the Forum rules on your way in. Please read them now (there is also a link at bottom right of each page) - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. See you soon with a legitimate question I hope. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts