Sign in to follow this  
Followers 0
wyattbiker

Can autoscript help me clipboard text under the cursor in any application

4 posts in this topic

Hi,

My specific need is to be able to highlight the phone number under the mouse cursor in applications such as PDFs, Office, Notepad, etc (just text, not on images) and then paste it in to the clipboard and pass it on to an application.

An example of a phone number would be 800-555-1212 or 1-800-callthisnumber or some other pattern that I can define using regex.

Here is the logic.

#1) Highlight text up to a space in directions of the word under the mouse cursor.

#2) Capture it into the clipboard

#3) Do a pattern match for phone number.

#4) Pass it on to an external  application (to a browser or something else)

The problem is double click alone will not do it since double click only highlights alphanumeric text but not special characters such as (-) and (@) and (.) and ()  for example.

Any ideas?

Thank you!

 

1 person likes this

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Try this out...mouse over the number, and send Control+g...will only work on application inputs, word docs, etc:

; control g
AutoItSetOption("SendKeyDownDelay",15)
AutoItSetOption("SendKeyDelay",15)
HotKeySet("^g", "GetPhoneNumber")

While True
WEnd

Func GetPhoneNumber()
    ClipPut("")
    MouseClick("Primary")
    $hwnd = WinGetHandle("[ACTIVE]")
    ; Select text backwards until space is found
    While True
;~      ControlSend($hwnd, "", "", "{SHIFTDOWN}")
        ControlSend($hwnd, "", "", "+{LEFT}")
;~      ControlSend($hwnd, "", "", "{SHIFTUP}")
        ControlSend($hwnd, "", "", "^c")
        Sleep(15)
        ConsoleWrite(StringRegExp(ClipGet(),"[^\w|^-]+",0) & " " & ClipGet()& @CRLF)
        If StringRegExp(ClipGet(),"[^\w|^-]",0) Then
            ControlSend($hwnd, "", "", "{RIGHT}")
            ExitLoop
        EndIf
    WEnd
    ; Select text forwards until space is found
    While True
;~      ControlSend($hwnd, "", "", "{SHIFTDOWN}")
        ControlSend($hwnd, "", "", "+{RIGHT}")
;~      ControlSend($hwnd, "", "", "{SHIFTUP}")
        ControlSend($hwnd, "", "", "^c")
        Sleep(15)
        ConsoleWrite(ClipGet()& @CRLF)
        If StringRegExp(ClipGet(),"[^\w-]",0) Then
            ControlSend($hwnd, "", "", "+{LEFT}")
            ExitLoop
        EndIf
    WEnd
    ConsoleWrite("FINAL........." & ClipGet() & @CRLF)
EndFunc

For things like web pages, you would have to loop mouseclick moves, with shift down, to highlight more or less

Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It logic works but autoit is not reliable (throws in c character sometimes and also very slow). But it is a good starting point. Thank you.

Edited by wyattbiker

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