Jump to content
Sign in to follow this  
kjpolker

How to read a radio button as a mouse click?

Recommended Posts

kjpolker

So I made a simple auto mouse clicker and I was wondering how I can define my radio1 as a left mouse click and my radio2 as a right mouse click, so when reading the function:

Func Sendinformation()
    Local $X, $Y
    MouseClick('', GUICtrlRead($X), GUICtrlRead($Y), 1, GUICtrlRead($Input3) * 100)
EndFunc

It will input either left or right mouse in the first set of brackets, any help? Thanks!

Share this post


Link to post
Share on other sites
Melba23

kjpolker,

This should give you an idea of how to go about it:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

GUIStartgroup($hGUI)
$hRadio_L = GUICtrlCreateRadio("Left", 10, 10, 50, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$hRadio_R = GUICtrlCreateRadio("Right", 10, 50, 50, 20)

$hLabel = GUICtrlCreateLabel("", 10, 100, 200, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If GUICtrlRead($hRadio_L) = 1 Then
        GUICtrlSetData($hLabel, "Left")
    Else
        GUICtrlSetData($hLabel, "Right")
    EndIf

WEnd

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
kjpolker

Ok now I just can't get it to loop the selected number of times, here is the code:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            If GUICtrlRead($LeftRadio) = 1 Then
        GUICtrlSetData($hLabel, "Left")
    Else
        GUICtrlSetData($hLabel, "Right")
    EndIf
        Case $Button1
            MouseClick(GUICtrlRead($hLabel), GUICtrlRead($Xinput), GUICtrlRead($Yinput), 1, GUICtrlRead($Input3) * 1000)
    EndSwitch
WEnd

It will go to the coord and I assume it will click but it will only click once, I want it to read $input3 and multiply it by 1000 to get the miliseconds, and it wont continuously click for some reason. And sorry Melba23 :)

EDIT: O and I just found out that it won't read right or left mouse clicks, it just makes it left click no matter what radio button is checked, so what do I do there? My guess is there is something wrong with the GUICtrlReads I have, because if there are no coordinates given in the inputs than it will click at 0,0. And I want it to click where the mouse currently is on the screen. Please help!

Edited by kjpolker

Share this post


Link to post
Share on other sites
Melba23

kjpolker,

This code is much closer to what you say you need:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

GUIStartgroup($hGUI)
$hRadio_L = GUICtrlCreateRadio("Left", 10, 10, 50, 20)
GUICtrlSetState(-1, $GUI_CHECKED)
$hRadio_R = GUICtrlCreateRadio("Right", 10, 50, 50, 20)

$iInput_X = GUICtrlCreateInput("", 200, 10, 100, 20)
$iInput_Y = GUICtrlCreateInput("", 200, 40, 100, 20)
$iInput_T = GUICtrlCreateInput("", 200, 70, 100, 20)

GUICtrlCreateLabel("X", 170, 10, 30, 20)
GUICtrlCreateLabel("Y", 170, 40, 30, 20)
GUICtrlCreateLabel("T", 170, 70, 30, 20)

$hButton1 = GUICtrlCreateButton("Start", 10, 200, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton1
            ; read radios and set correct mouse button
            If GUICtrlRead($hRadio_L) = 1 Then
                $sMouse_Button = "left"
            Else
                $sMouse_Button = "right"
            EndIf
            ; Get position parameters
            $iX_Pos = GUICtrlRead($iInput_X)
            $iY_Pos = GUICtrlRead($iInput_Y)
            ; If no inputs then click at mouse position
            If $iX_Pos = "" And $iY_Pos = "" Then
                $aMouse_Pos = MouseGetPos()
                $iX_Pos = $aMouse_Pos[0]
                $iY_Pos = $aMouse_Pos[1]
            EndIf
            ; Read repeat delay in seconds and transform to ms
            $iT_ms = GUICtrlRead($iInput_T) * 1000
            ; Start a loop to repeatedly click the mouse
            While 1
                ; Click mouse
                ;MouseClick($sMouse_Button, $iX_Pos, $iY_Pos, 1)  ; <<<<<<<<<<<<<<<<<<<<<<<<<<< uncomment this
                ConsoleWrite($sMouse_Button & " - " & $iX_Pos & " - " & $iY_Pos & " - " & $iT_ms & @CRLF) ; <<<<<<<< delete this
                ; We need a second loop to wait for $iT_ms - if we use Sleep. the script is unresponsive and we cannot stop it
                $iBegin = TimerInit()
                While TimerDiff($iBegin) < $iT_ms
                    If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit ; Exit if teh gui is closed
                WEnd
                ; or we keep looping to click the mouse again
            WEnd

    EndSwitch

WEnd

If you do not enter any position input, the mouse will click where the mouse is - which, as you have to press the Start button, is always on the Start button at about 650 x 500. You will have change the code a lot if you want it to follow the mouse around - or if you want to alter the parameters of the click.

Please do not take this the wrong way, but looking at your last post and seeing how you just stuffed a few lines from my hint at random into your existing code, I think you could do with learning a bit more about scripting. Could I suggest the excellent tutorials that you will find here and here. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
kjpolker

I will take a look at those tutorials and thanks for the help, but the reason I ask questions on forums is cause I literally don't have any idea on it, I can come up with a near finished program but there are just those little fancy things that I don't know of, and I don't stuff codes from people into mine, cause I don't learn anything that way, what I do is I read it and manually retype it and try to understand it, but for the radion buttons, I didn't understand them at all on how they work. Now that I have seen your coding I found out what you did and why, and why mine wasn't working so now in the future I don't need to ask how a radio buttons interacts with other parts.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.