Jump to content

Detect mouse highlight


Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

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