Jump to content

List text one character at a time - (Moved)


g52
 Share

Recommended Posts

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

$edit1 is the control id of your edit box :huh2:

The script provided by @peters1956 will add text at the end, but if you want to insert the text anywhere in the edit, take a look at the function mentioned above ^^

Link to comment
Share on other sites

1 hour ago, Nine said:

$edit1 is the control id of your edit box :huh2:

The script provided by @peters1956 will add text at the end, but if you want to insert the text anywhere in the edit, take a look at the function mentioned above ^^

I do not understand you so much :(

 

like this?

 

#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <WindowsConstants.au3>

$sStringToInsert = "Jackdaws love my big sphinx of quartz."
For $i = 1 to StringLen($sStringToInsert)
   _GUICtrlEdit_InsertText(StringMid($sStringToInsert, $i, 1))
    Sleep(50)
Next

 

 

Edited by g52
Link to comment
Share on other sites

Ok here what you gonna do.  You will open help file, go to _GUICtrlEdit_InsertText function, read and understand the documentation, then open the example, and try modify it to fit your needs.  After that if you still need some more help, come back with a runable script (this means, a script that we can run without any errors).

Link to comment
Share on other sites

Just now, g52 said:

How do I insert text from the textbox one character at a time where the cursor is located?

I may be mistaken, but can _GUICtrlEdit_InsertText() be easily used when OP needs the text to be inserted at caret position ?

Anyway, here is a simple example using GUICtrlSetData() , where the 3rd parameter is... Nine :)

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

GUICreate("Insertion at caret place", 400, 300)
$idEdit = GUICtrlCreateEdit("- It was written :" & @CRLF & "<  >" & @CRLF & _
    "- Really ?", 2, 2, 394, 268)
GUISetState(@SW_SHOW)

MsgBox($MB_TOPMOST, '', 'Click the caret between "<>" in the edit control' & @CRLF & _
    'Then press Ok')

$sStringToInsert = "Jackdaws love my big sphinx of quartz"
For $i = 1 to StringLen($sStringToInsert)
    GUICtrlSetData($idEdit, StringMid($sStringToInsert, $i, 1), 9) ; 9 or anything but ""
    Sleep(100)
Next

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()

496395941_caretinedit.png.e3a27025e68f55708bb73207549d6a02.png

Edited by pixelsearch
maybe to may be
Link to comment
Share on other sites

@pixelsearch Yes you can do it with using _GUICtrlEdit_GetSel () to obtain the caret position, then _GUICtrlEdit_InsertText() to add chars.  But I was totally unaware of the GUICtrlSetData trick.  Nice find.

Link to comment
Share on other sites

1 hour ago, pixelsearch said:

@pixelsearch

It works 🙂

Why does the text appear only in the "Insertion at caret place" window? I want it to work wherever I put the cursor. CMD, browser, text editor etc ..

Thank you very much.

 

Link to comment
Share on other sites

In that case, you will need to direct your text to the control or window you wish to have your text appear in.  In the example I gave, the text was to appear in an Edit control, $Edit1, in an AutoIt GUI.  If you wanted the text to appear in Notepad, then you would need to use Send to send the text to Notepad when it was the active window.  There is a tutorial in the help file for this.

Link to comment
Share on other sites

#include <GuiEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIMisc.au3>

Global $hEdit
gui1()

Func gui1()
Local $Old_String
Local $New_String

    Local $hGUI1 = GUICreate("Gui 1", 300, 400, 100, 100)
    Local $idEdit1 = GUICtrlCreateEdit("write something", 5, 5, 280, 150)
    
    ; ------------------ Start of formatting text ----------------------------------------------
    ; --- Format text i.e. add trailing newline, and, insert a space between all fullstops or comas and newlines. -----
    If StringRegExp(GUICtrlRead(-1), "\v+$") = 0 Then GUICtrlSetData(-1, GUICtrlRead(-1) & @CRLF)
    GUICtrlSetData(-1, StringRegExpReplace(GUICtrlRead(-1), "(\V)(\v)", "\1 \2"))
    ; ------------------ End of formatting text ------------------------------------------------
    
    Local $idEdit2 = GUICtrlCreateEdit("", 5, 200, 280, 150)
    $hEdit = GUICtrlGetHandle($idEdit1)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
        ; ---
        If _WinAPI_GetFocus() = $hEdit Then
            $Old_String = $New_String
            $New_String = Hover_WordDetect()
                If $Old_String <> $New_String Then
                    GUICtrlSetData($idEdit2, Hover_WordDetect() & " ", 1)
                EndIf
        EndIf
        ; ---
    WEnd

EndFunc   ;==>gui1


Func Hover_WordDetect()
;code by @Malkey 
;https://www.autoitscript.com/forum/topic/157899-get-text-word-under-the-mouse-pointer/
    Local $aCharPos[2], $iMousePos[2]
    $aCharPos = _GUICtrlEdit_CharFromPos($hEdit, _WinAPI_GetMousePosX(True, $hEdit), _WinAPI_GetMousePosY(True, $hEdit))
    Local Const $sLine = _GUICtrlEdit_GetLine($hEdit, $aCharPos[1])
    $aCharPos[0] -= _GUICtrlEdit_LineIndex($hEdit, $aCharPos[1])
    ;ConsoleWrite($aCharPos[0] & @LF)
    If StringMid($sLine, $aCharPos[0] + 1, 1) == " " Then
        Return ""
    Else
        Return StringRegExpReplace($sLine, "(?s)^.{0," & $aCharPos[0] & "}(?: |^)([^ ]*).*$", "\1")
    EndIf
EndFunc   ;==>Hover_WordDetect

 

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...