Jump to content

Highlight text under the current position of the mouse cursor?


Recommended Posts

Hi friends,

I have searched this forum thoroughly but I couldn't find my answer yet.

Basically I would like to write an AutoIt script to highlight any text (which could be a word, a character, ...) which is under the current position of the mouse cursor. Is this possible? If Yes, please suggest me a way to do it.

Thank you very much.

Link to comment
Share on other sites

This is not easy and methods will vary depending on circumstances. If you try to do this with an edit control that you created yourself then it should be quite feasible. You will need to use StringRegExp to identify the word at the coordinates. You could find the character nearest the mouse using MouseGetPos combined with _GUICtrlEdit_CharFromPos. However all this seems rather complicated to me.

Edited by czardas
Link to comment
Share on other sites

This is not easy and methods will vary depending on circumstances. If you try to do this with an edit control that you created yourself then it should be quite feasible. You will need to use StringRegExp to identify the word at the coordinates. You could find the character nearest the mouse using MouseGetPos combined with _GUICtrlEdit_CharFromPos. However all this seems rather complicated to me.

Hi czardas,

Thank you for your response. However I would like my program to highlight text in any situation, no matter what I am doing. Several examples are reading pdf files, surfing the web, composing email and docs, etc.

So in your opinion this task cannot be done with AutoIt?

Link to comment
Share on other sites

So you're reading some text that's on your screen, you see a word that you want to highlight, you move the cursor to that word and hit the HotKey to start the script and it Send's a double click (which selects whatever text is at the cursor postion). Does this meet your scenario? If so, this can probably be done this simply, but maybe not..

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

So you're reading some text that's on your screen, you see a word that you want to highlight, you move the cursor to that word and hit the HotKey to start the script and it Send's a double click (which selects whatever text is at the cursor postion). Does this meet your scenario? If so, this can probably be done this simply, but maybe not..

The functionality you described is exactly what I intend to do. However, if we are handling a hyperlink, we cannot send a double click to it, because if we do so, we would be navigated to the address pointed to by the hyperlink, and the text would not be highlighted in this case.

Do you have any idea for special cases like that?

Edited by bobbyab9987
Link to comment
Share on other sites

  • 2 years later...

Hi everyone.

I am very new to AutoIt, and I must thank you all for your support and help.

In regards to this issue, I am using AutoIt to look for any word in RED and double click on > my search returns one hit though so you might want to update the script.

$pixel = PixelSearch(1242,212,1765,466,0xFF0000)
 
If IsArray($pixel) = True Then
  MouseMove($pixel [0], $pixel [1], 1)
EndIf
 
MouseClick("left",$pixel [0], $pixel [1],2)

 

-0mar4fendi

Link to comment
Share on other sites

  • Moderators

0mar4fendi,

Welcome to the AutoIt forums. :)

But if you really must post in a fairly old thread, please at least post something relevant. :naughty:

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

  • 1 year later...

Melba23, actually it is your post the one that does not contribute to this forum.

For those interested, based on 0mar4fendim reply, I was able to complete a tiresome task.

Here is my approach:

; Triger search
Send("^f")
Sleep(500)
Send("@")
Sleep(500)
Send("{ENTER}")
Sleep(2000)

;Find , in Chrome, the higlighted @ sign, yellow pixel
$pixel = PixelSearch(470,193, 845,248, 0xffff00)


;Copy e-mail from X-OnlineApp
MouseClick($MOUSE_CLICK_SECONDARY, $pixel[0], $pixel[1], 1, 0)
Sleep(500)
Send("e")
Sleep(1000)

 

Thanks 0mar4fendim, that is a very creative approach.

- And yes I know this is an old post; however, even today people may have the same problem.

 

 

---
vicsar
https://about.me/vicsar
 

 

Link to comment
Share on other sites

  • Moderators

vicsar,

Thanks for that - I will give myself a stern talking-to sometime later this evening.

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