g52 Posted December 2, 2019 Share Posted December 2, 2019 Hello. How do I insert text from the textbox one character at a time where the cursor is located? Thank you Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 2, 2019 Moderators Share Posted December 2, 2019 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 More sharing options...
peters1956 Posted December 2, 2019 Share Posted December 2, 2019 (edited) You could try this: $sStringToInsert = "Jackdaws love my big sphinx of quartz." For $i = 1 to StringLen($sStringToInsert) GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & StringMid($sStringToInsert, $i, 1)) Sleep(150) Next Edited December 2, 2019 by peters1956 Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2019 Share Posted December 2, 2019 Look in help file for _GUICtrlEdit_InsertText (....) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
g52 Posted December 2, 2019 Author Share Posted December 2, 2019 (edited) 1 hour ago, peters1956 said: You could try this: $sStringToInsert = "Jackdaws love my big sphinx of quartz." For $i = 1 to StringLen($sStringToInsert) GUICtrlSetData($Edit1, GUICtrlRead($Edit1) & StringMid($sStringToInsert, $i, 1)) Sleep(150) Next Thank you. I get an error after starting Edited December 2, 2019 by g52 Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2019 Share Posted December 2, 2019 $edit1 is the control id of your edit box 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 ^^ “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
g52 Posted December 2, 2019 Author Share Posted December 2, 2019 (edited) 1 hour ago, Nine said: $edit1 is the control id of your edit box 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 December 2, 2019 by g52 Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2019 Share Posted December 2, 2019 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). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pixelsearch Posted December 2, 2019 Share Posted December 2, 2019 (edited) 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() Edited December 2, 2019 by pixelsearch maybe to may be Musashi 1 Link to comment Share on other sites More sharing options...
Nine Posted December 2, 2019 Share Posted December 2, 2019 @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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
g52 Posted December 2, 2019 Author Share Posted December 2, 2019 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 More sharing options...
peters1956 Posted December 4, 2019 Share Posted December 4, 2019 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 More sharing options...
junkew Posted December 4, 2019 Share Posted December 4, 2019 Use send command to just send strings of text whereever you want. https://www.autoitscript.com/autoit3/docs/functions/Send.htm FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
jugador Posted December 4, 2019 Share Posted December 4, 2019 expandcollapse popup#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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now