Jump to content

How to read the 'text' value from an input field?


Go to solution Solved by ioa747,

Recommended Posts

> in this shot icons 2 and 3 do not exist for me   

You're referencing the blue chevron, and the red x icons on the left?  If so, those are 'Continue task' and 'Cancel task' respectively.  I guess they are present because this screenshot is technically part of a ShareX 'After workflow task?'  That is just an educated guess though.

Let me try to explain my question again.

Your code contains AutoIt code to do the following in ShareX:

  • Automatically create a rectangle, then change its border size.
  • Automatically create an arrow, then change its border size and arrow head direction.

What I would like to do is slightly different:

  • Before any AutoIt code is executed, I will manually create either a rectangle or an arrow in ShareX.
  • After the shape has been created on-screen, execute AutoIt code to automatically change the border size, regardless of whether a rectange or arrow is selected.  This code should not require any additional user input, 

Would you agree that my primary issue is the following:  How will my AutoIt code know exactly where to click to open 'Tool options?'  

If so, thoughts?  I guess as a last resort I can choose a pixel that will have COLOR-A if rectangle is selected, and COLOR-B if arrow is selected.  Then my code can read the color of this pixel, which should then tell it where to click in order to open 'Tool options.

Link to comment
Share on other sites

On 6/28/2023 at 5:37 PM, cag8f said:

I guess as a last resort I can choose a pixel that will have COLOR-A if rectangle is selected

line     43-58

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7

;~ ShareXMenu("Send", "r") ;Rectangle
MouseClickDrag("left", 100, 100, 300, 300)
ShareXMenu("Set_ToolOptions", "BorderSize=5") ;set BorderSize

;----------------------------------------------------------------------------------------
Func ShareXMenu($sCommand, $sOption)
;~ https://getsharex.com/docs/keybinds#tools
;~ Tools
;~ Keybind  Description
;~ Send, "m"    Select and move
;~ Send, "r"    Rectangle
;~ Send, "e"    Ellipse
;~ Send, "f"    Freehand
;~ Send, "l"    Line
;~ Send, "a"    Arrow
;~ Send, "o"    Text (Outline)
;~ Send, "t"    Text (Background)
;~ Send, "s"    Speech balloon
;~ Send, "i"    Step
;~ Send, "b"    Blur
;~ Send, "p"    Pixelate
;~ Send, "h"    Highlight
;~ Send, "c"    Crop image
;~ Send, "x"    Cut out
;~
;~ Click, 190  Click on 190=Select and move
;~ Set_ToolOptions, "BorderSize=5"  Set BorderSize to 5
;~ Set_ToolOptions, "BorderStyle=DashDot"  Set BorderStyle to DashDot
;~ Set_ToolOptions, "ArrowHeadDirection=Both"  Set Arrow Head Direction to Both

    ;window handle
    Local $hWnd = WinWait("ShareX - Editor menu", "", 3)
    If Not $hWnd Then Exit ConsoleWrite("! exit ShareX Not exist" & @CRLF)
    Local $hWndImageEditor = WinGetHandle("ShareX - Image editor")
    Local $aWinPos = WinGetPos($hWnd)
    Local Const $iSZ = $aWinPos[3] / 2 ; - 16
    Local Static $sActiveTool = "SelectAndMove" ;Select and move
    Local $hWndToolOptions, $ilPos, $aSplt
    WinActivate($hWnd)

    ;Get  tools with PixelSearch
    Local $aArea[] = [1290, 20, 1345, 50] ;SearchArea left,top,right,bottom I guess +70 for you = [1360, 20, 1415, 50]
    Local $SearchColor = 0x7A8CA1 ;Light slate gray 0x7A8CA1 is  the gray from the ToolOptions icon with Nord Dark theme
    Local $aCoord = PixelSearch($aArea[0], $aArea[1], $aArea[2], $aArea[3], $SearchColor, 6)

    If @error Then
        ConsoleWrite("! Error X and Y" & @CRLF)
    Else
        ConsoleWrite("Pixel Found at  X and Y are: " & $aCoord[0] & "," & $aCoord[1] & @CRLF)
        If $aCoord[0] > 1300 Then ; I guess +70 for you = 1370
            $sActiveTool = "Rectangle"
        Else
            $sActiveTool = "Arrow"
        EndIf
    EndIf

    ConsoleWrite("-> $sActiveTool:" & $sActiveTool & @CRLF)

    Switch $sCommand
        Case "Send"
            ;ConsoleWrite("- Send:" & $sOption & @CRLF)
            Switch $sOption
                Case "r"    ;Rectangle
                    $sActiveTool = "Rectangle"
                Case "a"    ;Arrow
                    $sActiveTool = "Arrow"
                Case Else
                    $sActiveTool = "SelectAndMove"
            EndSwitch
            WinActivate($hWndImageEditor)
            Sleep(20)
            Send($sOption)
        Case "Click"
            $sOption = Int($sOption)
            ;ConsoleWrite("- Click:" & $sOption & @CRLF)
            ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r22_ad11", "left", 1, $sOption, $iSZ)
            ;MouseMove($aWinPos[0] + $sOption, $aWinPos[1] + $iSZ)
        Case "Set_ToolOptions"
            ;ConsoleWrite("- Set_ToolOptions:" & $sOption & @CRLF)
            Switch $sActiveTool
                Case "Rectangle"  ;Rectangle
                    $ilPos = 869  ; * <- give here the Rectangle ToolOptions position
                    ConsoleWrite("- Rectangle $ilPos=" & $ilPos & @CRLF)
                    ;first click Tool Options
                    ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r22_ad11", "left", 1, $ilPos, $iSZ)
                    $hWndToolOptions = WinWait("[CLASS:WindowsForms10.Window.808.app.0.1a52015_r22_ad1]", "", 3)
                    If Not $hWndToolOptions Then Exit ConsoleWrite("! exit Not $hWndToolOptions" & @CRLF)
                    $aSplt = StringSplit($sOption, "=")
                    If $aSplt[0] <> 2 Then Exit ConsoleWrite("! exit" & @CRLF)
                    Switch $aSplt[1]
                        Case "BorderSize"
                            ControlSetText($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad11", $aSplt[2] & @CRLF)
                            Sleep(20)
                            ControlSend($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad11", "{TAB}{ESC}")
                        Case "CornerRadius"
                            ControlSetText($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad12", $aSplt[2])
                            Sleep(20)
                            ControlSend($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad12", "{ENTER}")
                        Case "BorderStyle"
                            ControlFocus($hWndToolOptions, "", "WindowsForms10.COMBOBOX.app.0.1a52015_r22_ad11")
                            Switch $aSplt[2]
                                Case "Solid"
                                    Send("s")
                                Case "Dash"
                                    Send("sd")
                                Case "Dot"
                                    Send("sdd")
                                Case "DashDot"
                                    Send("sddd")
                                Case "DashDotDot"
                                    Send("sdddd")
                            EndSwitch
                            Sleep(20)
                            ControlSend($hWndToolOptions, "", "WindowsForms10.COMBOBOX.app.0.1a52015_r22_ad11", "{TAB}{ESC}")
                    EndSwitch
                Case "Arrow"      ;Arrow
                    $ilPos = 843  ; * <- give here the Arrow ToolOptions position
                    ConsoleWrite("- Arrow $ilPos=" & $ilPos & @CRLF)
                    ;first click Tool Options
                    ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r22_ad11", "left", 1, $ilPos, $iSZ)
                    $hWndToolOptions = WinWait("[CLASS:WindowsForms10.Window.808.app.0.1a52015_r22_ad1]", "", 3)
                    If Not $hWndToolOptions Then Exit ConsoleWrite("! exit Not $hWndToolOptions" & @CRLF)
                    $aSplt = StringSplit($sOption, "=")
                    If $aSplt[0] <> 2 Then Exit ConsoleWrite("! exit  $aSplt[0] <> 2" & @CRLF)
                    Switch $aSplt[1]
                        Case "BorderSize"
                            ControlSetText($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad11", $aSplt[2] & @CRLF)
                            Sleep(20)
                            ControlSend($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad11", "{TAB}{ESC}")
                        Case "CornerRadius"
                            ControlSetText($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad12", $aSplt[2])
                            Sleep(20)
                            ControlSend($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad12", "{ENTER}")
                        Case "BorderStyle"
                            ControlFocus($hWndToolOptions, "", "WindowsForms10.COMBOBOX.app.0.1a52015_r22_ad11")
                            Switch $aSplt[2]
                                Case "Solid"
                                    Send("s")
                                Case "Dash"
                                    Send("sd")
                                Case "Dot"
                                    Send("sdd")
                                Case "DashDot"
                                    Send("sddd")
                                Case "DashDotDot"
                                    Send("sdddd")
                            EndSwitch
                        Case "ArrowHeadDirection"
                            ControlFocus($hWndToolOptions, "", "WindowsForms10.COMBOBOX.app.0.1a52015_r22_ad12")
                            Switch $aSplt[2]
                                Case "End"
                                    Send("e")
                                Case "Start"
                                    Send("s")
                                Case "Both"
                                    Send("b")
                            EndSwitch
                            Sleep(20)
                            ControlSend($hWndToolOptions, "", "WindowsForms10.COMBOBOX.app.0.1a52015_r22_ad12", "{TAB}{ESC}")
                    EndSwitch
                Case Else
                    Return SetError(1, 1, 0)
            EndSwitch
    EndSwitch
EndFunc   ;==>ShareXMenu
;----------------------------------------------------------------------------------------

 

Edited by ioa747
I changed the color

I know that I know nothing

Link to comment
Share on other sites

OK thanks very much for this!  Looks like it is exactly what I need.  Give me a few days to have a proper read/test.

Edit:  It does the trick (with a few mods).  So thanks for that!

Edited by cag8f
Link to comment
Share on other sites

@ioa747 I'm back 🙂  I'm still finalizing what I want, but have run into a new issue.

In short, I have code that does exactly what is desired/expected when I run it from within SciTE (by pressing F5).  But when I move that same code into a new .au3 file, and assign it to run when a keyboard shortcut is pressed, the code seems to skip the last step--i.e. the 'Tool options' dropdown remains open, as if no 'Enter' key press was sent (see screenshot below). 

Thoughts?  Here's a screenshot of the still-open 'Tool options.'  After that I've  posted both version of my code.

image.thumb.png.6caadf551c1b32e998570327cc7d5ac2.png

Naked code.  This is working as desired/expected when I run it via SciTE (with F5)--including the last `ControlSend` command.  Note:  When run, the code opens 'Tool options' and sets a value for 'Border Size.'  The last step in this code is one you added:  to send an "Enter" key press to the 'Border Size' control. 

Local $hWnd = WinWait("ShareX - Editor menu", "", 3)
Local $aWinPos = WinGetPos($hWnd)
Local Const $iSZ = $aWinPos[3] / 2 ; - 16
ConsoleWrite(ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r6_ad11", "left", 1, 1356-416, $iSZ) & @CRLF)
ControlSetText("[CLASS:WindowsForms10.Window.20808.app.0.1a52015_r6_ad1]", "", "WindowsForms10.EDIT.app.0.1a52015_r6_ad11", "1")
Sleep(50)
ControlSend("[CLASS:WindowsForms10.Window.20808.app.0.1a52015_r6_ad1]", "", "WindowsForms10.EDIT.app.0.1a52015_r6_ad11", "{ENTER}")

Keyboard shortcut code. Executing this code, via its keyboard shortcut, leaves the 'Tool options' dropdown open:

Opt("SendKeyDelay", 0) ; 0 removes completely the delay
Opt("SendKeyDownDelay", 0) ; 0 removes completely the delay

Local $kb_sxb = "!^v"; define keyboard shortcut to toggle ShareX border size between 1 and 5. Uses ctrl+alt+v.

HotKeySet($kb_sxb, "send_sxb")

Func send_sxb(); Check value of ShareX border size.  If 5, change to 1.  Otherwise, change to 5.
    HotKeySet($kb_sxb) ; deactivate the hotkey in case the user presses it too long

    ;Begin naked code that I copied from previous .au3 file.
    Local $hWnd = WinWait("ShareX - Editor menu", "", 3)
    Local $aWinPos = WinGetPos($hWnd)
    Local Const $iSZ = $aWinPos[3] / 2 ; - 16
    ConsoleWrite(ControlClick($hWnd, "", "WindowsForms10.Window.8.app.0.1a52015_r6_ad11", "left", 1, 1356-416, $iSZ) & @CRLF)
    ControlSetText("[CLASS:WindowsForms10.Window.20808.app.0.1a52015_r6_ad1]", "", "WindowsForms10.EDIT.app.0.1a52015_r6_ad11", "1")
    Sleep(50)
    ControlSend("[CLASS:WindowsForms10.Window.20808.app.0.1a52015_r6_ad1]", "", "WindowsForms10.EDIT.app.0.1a52015_r6_ad11", "{ENTER}")
    ;End naked code that I copied from previous .au3 file.

    HotKeySet($kb_sxb, "send_sxb"); reactivate it
EndFunc

 

Link to comment
Share on other sites

yes, I also encountered some problems with the enter (and it also gave me an audio notification as an error - Default Beep)
if you noticed in the last post I replaced it with a tab for updating and an esc for closing

ControlSend($hWndToolOptions, "", "WindowsForms10.EDIT.app.0.1a52015_r22_ad11", "{TAB}{ESC}")

 

I know that I know nothing

Link to comment
Share on other sites

  • 1 month later...

As mentioned by @mLipok, you can use regexp to find the control handle based on CLASS (not CLASSNN).  Something like this could work if there is no other control having the same pattern :

Local $hCrlt = ControlGetHandle($hWnd, "", "[REGEXPCLASS:WindowsForms10\.Window\.8\.app\.0\.[a-z0-9]{7}_r6_ad\d*]"

Notice the \d* at the end, since I do not know if you gave a CLASSNN (I supposed so), I made it search for some optional numbers.  You can also combine with other parameters like X/YW/H, INSTANCE, etc (see help file).

Edited by Nine
added precision
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...