Sign in to follow this  
Followers 0
byronsmith

Detect mouse highlight

8 posts in this topic

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

Share this post


Link to post
Share on other sites



byronsmith,

"Vague" is exactly the word for that question! :P

how to detect when I've highlighted a word on any application

Do you want to detect when your mouse is over highlighted text as this extract from your post suggests

upon moving my mouse over this WORD it will begin to highlight it

or do you want to highlight a particular word just by moving the mouse over it as this second extract seems to request? :x

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

byronsmith,

Does that clear it up a little more?

Limpid in its clarity - and this is how you might do it: :x

#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? :P

M23

Edit: Typnig!

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by byronsmith

Share this post


Link to post
Share on other sites

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0