Jump to content

Recommended Posts

Posted

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.

#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
Posted (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 by Kraviks
Posted

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.

Posted (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 by mikell
Posted

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.

#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
Posted

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

#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 ?

  • Moderators
Posted

Kraviks,

 

a macro for DC Universe Online

Unfortunately 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. :naughty:

See you soon with a legitimate question I hope. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...