piterek Posted May 10, 2010 Share Posted May 10, 2010 Hi!A simple question is:How to get "word" from edit's caret position??Example: - I have some text in notepad ("word1 word2 word3 word4...")Now I set caret position somewhere inside "word2", and I want return from control only this "word2"It's something like use ControlCommand function with "GetSelected", "" but I want return text without marking wordThis function was used eg. AutoIt3 FuncPopUp Link to comment Share on other sites More sharing options...
Developers Jos Posted May 10, 2010 Developers Share Posted May 10, 2010 FuncPopUp is using some SciTE Director calls to get the word at the cursors active location and cannot easily be copied to notepad. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 10, 2010 Moderators Share Posted May 10, 2010 piterek, Here is a way to do it: #Include <GuiEdit.au3> ; Start Notepad and enter some text, then start script ; Wait for Notepad to be active WinWaitActive("[CLASS:Notepad]") ; Get handle for Edit control $hNotePadEdit = ControlGetHandle("[CLASS:Notepad]", "", "[CLASS:Edit; INSTANCE:1]") ; Where is caret? $aCaretPos = _GUICtrlEdit_GetSel($hNotePadEdit) ; Where is beginning of line? $iLineStartPos = _GUICtrlEdit_LineIndex($hNotePadEdit, -1) ; Get text of the line $sLine = _GUICtrlEdit_GetLine($hNotePadEdit, _GUICtrlEdit_LineFromChar($hNotePadEdit, -1)) ; Find ends of current word $iStartPos = StringInStr($sLine, " ", 0, -1, $aCaretPos[0] - $iLineStartPos) $iEndPos = StringInStr($sLine, " ", 0, 1, $aCaretPos[0] - $iLineStartPos) If $iEndPos = 0 Then $iEndPos = StringLen($sLine) + 1 ; Extract word $sWord = StringMid($sLine, $iStartPos + 1, $iEndPos - $iStartPos - 1) ; Display word MsgBox(0, "Found", $sWord) Ask if anything is unclear. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Developers Jos Posted May 10, 2010 Developers Share Posted May 10, 2010 ok... I stand corrected ... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
funkey Posted May 10, 2010 Share Posted May 10, 2010 Another way without GuiEdit.au3 Global $hNotePad = WinGetHandle("[Class:Notepad]") HotKeySet("{Esc}", "_Exit") HotKeySet("^g", "_GetWordFromCaret") While 1 Sleep(10000) WEnd Func _GetWordFromCaret() Local $sRet Local $iLine = ControlCommand($hNotePad, "", "Edit1", "GetCurrentLine", "") Local $iCol = ControlCommand($hNotePad, "", "Edit1", "GetCurrentCol", "") Local $sLine = ControlCommand($hNotePad, "", "Edit1", "GetLine", $iLine) If StringMid($sLine, $iCol, 1) = " " Then $iCol -= 1 Local $iFirst = StringInStr($sLine, " ", 0, -1, $iCol) $sLine = StringTrimLeft($sLine, $iFirst) Local $iLast = StringInStr($sLine, " ", 0, 1) If $iLast <> 0 Then $sLine = StringLeft($sLine, $iLast - 1) EndIf ConsoleWrite($sLine & @CR) EndFunc Func _Exit() Exit EndFunc Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. 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