byronsmith Posted December 10, 2010 Share Posted December 10, 2010 Hi All, Very quick question, I've searched the forums for my term but nothing stands out from any of the posts. I'm trying to figure out how to detect when I've highlighted a word on any application. I don't want to automatically highlight it, just to be clear but upon moving my mouse over this WORD it will begin to highlight it. Is there a way that I can detect when highlighting has began and how to retrieve what it is that is currently being highlighted. If there some DLL call I could use? Sorry for the vagueness but I'm not sure how else to explain it? Regards Byron Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 10, 2010 Moderators Share Posted December 10, 2010 byronsmith,"Vague" is exactly the word for that question! how to detect when I've highlighted a word on any applicationDo you want to detect when your mouse is over highlighted text as this extract from your post suggestsupon moving my mouse over this WORD it will begin to highlight itor do you want to highlight a particular word just by moving the mouse over it as this second extract seems to request? 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...
byronsmith Posted December 10, 2010 Author Share Posted December 10, 2010 M23, Lets try simplify this ha ha. On this very sentence, if you put your mouse over this X, hold your left mouse button and begin dragging your mouse to either the right you'll notice the sentence will being to highlight in blue (using Windows 7). I want to detect when this has began. Does that clear it up a little more? Regards Byron Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 10, 2010 Moderators Share Posted December 10, 2010 (edited) byronsmith, Does that clear it up a little more?Limpid in its clarity - and this is how you might do it: expandcollapse popup#include <GUIConstantsEx.au3> #Include <GuiEdit.au3> #include <Misc.au3> $dll = DllOpen("user32.dll") $sMsg = "Highlighting" $hGUI = GUICreate("Test", 500, 500) $hEdit = GUICtrlCreateEdit("This is a chunk of text", 10, 10, 480, 300) $hLabel = GUICtrlCreateLabel("", 10, 330, 200, 20) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE DllClose($dll) Exit EndSwitch ; If mouse pressed and we have not yet started highlighting If _Ispressed("01", $dll) And GUICtrlRead($hEdit) <> $sMsg Then ; Check if we are indeed highlighting $aSel = _GUICtrlEdit_GetSel($hEdit) If $aSel[0] <> $aSel[1] Then ; If we are - tell us unless we already were If GUICtrlRead($hLabel) <> $sMsg Then GUICtrlSetData($hLabel, $sMsg) Else ; If not - stop telling us GUICtrlSetData($hLabel, "") EndIf EndIf WEnd All clear? M23 Edit: Typnig! Edited December 10, 2010 by Melba23 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...
byronsmith Posted December 10, 2010 Author Share Posted December 10, 2010 yes, exactly, well almost exactly. I'm looking to detect this on say a normal notepad or web page. But you've pointed me in the right direction and so I'll have a crack at it myself. Thank you so much! Byron Link to comment Share on other sites More sharing options...
byronsmith Posted December 15, 2010 Author Share Posted December 15, 2010 Ok so I finally got a chance to have a crack at this however this isn't going to work with that function GetSel as that only gives me the starting and ending points and not the actual text. Also, I think this can only be done on the CtrlEdit on a create GUI. Is there anyway I can determine the highlighted text as it's highlighting but on any window that is active i.e Firefox, Notepad, Outlook etc? Regards Byron Link to comment Share on other sites More sharing options...
byronsmith Posted December 15, 2010 Author Share Posted December 15, 2010 (edited) At a guess, I think I need to retrieve the handle of the active window. $handle = WinGetHandle ("[ACTIVE]") Then using a similar function like this: $selection = _GUICtrlWindow_GetSel($handle) Which should produce the results but as the text not the character position MsgBox(4096, "Handle", $selection ) Edited December 15, 2010 by byronsmith Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 15, 2010 Moderators Share Posted December 15, 2010 byronsmith, This will tell you what you have highlighted (highlit?) in any app but you have to release the mouse button to get the value to show: HotKeySet("{ESC}", "On_Exit") Func On_Exit() Exit EndFunc ClipPut("") $sCurrText = "" While 1 ; Copy what is highlighted Send("^c") ; Read what was collected $sText = ClipGet() If $sText <> $sCurrText Then $sCurrText = $sText ConsoleWrite($sText & @CRLF) EndIf Sleep(10) WEnd I am working on it. 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...
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