Jump to content
drquochoai

How to get the selected text at any application without send("^c")

Recommended Posts

drquochoai

I'm using this code :

HotKeySet("^q", "_hd")
While 1
WEnd
Func _hd()
   $oldClip = ClipGet(); get the data that is currently in the clipboard
   Send('^c'); copy the selected text to the clipboard
   $phrase = ClipGet(); get the data from the clipboard (which is now the selected word)
   ClipPut($oldClip); put the old data back in the clipboard
   ConsoleWrite($phrase& @CRLF)
EndFunc

First time of running, he do too good his job, but the second time i press Ctrl+Q, he can not get the selected text that i want.

I don't know why, but i've spent 2 days with this problem, i just wonder if we can use CMD or ObjCreate function to do that, without using Send() function with lots of buggy inside.

Hope you can help.

Thanks so much.

Share this post


Link to post
Share on other sites
water

First you should insert a Sleep statement into your loop. Else it will eat up all available CPU.

While 1
    Sleep(10)
WEnd

Second: You are sure that the application where you marked the text does support Ctrl+c?

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
drquochoai

thanks for your tip, now i can do it:

Func _copyAnyWhere()
    $window_title = WinGetTitle("[active]")
    WinActivate($window_title)
    $readtext = ""

    For $i = 1 to 2 Step 1

        $rand = random (1, 4, 1)

        Send ("{CTRLDOWN}")
        Switch $rand
            Case 1
                Send("{INS}")
            Case 2
                ControlSend($window_title, "", "", "{INS}")
            Case 3
                Send("c")
            Case 4
                ControlSend($window_title, "", "", "c^")
        EndSwitch

        Send ("{CTRLUP}")

        $readtext = ClipGet()
        If $readtext <> "" Then
            return $readtext
        EndIf

        If $i = 4 Then
            WinActivate($window_title)
            Sleep(100)
        EndIf
    Next
    return $readtext
EndFunc

We can not send Ctrl, but we can send one key, so that we will hold control then send a key.

I found it in our forum, thanks so much.

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

×