Jump to content

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


drquochoai
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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.

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