Jump to content

Recommended Posts

Posted

I like to do autoit detects select text with the mouse or keyboard?

I want to make a program that when you highlight a text then appears automatically a window that has buttons to copy and paste to the clipboard or translated into google.

Posted (edited)

I do not remember who to thank sincerely for this, but I use it in various scripts, it works like a charm:

Func _GetTextFromActiveWindow()

    ;Get window title, in case we need it
    $window_title = WinGetTitle("[active]")

    If $window_title == "" Then
        Beep(600, 1000)
        Exit
    EndIf

    WinActivate($window_title)

    ClipPut("") ;Clear the clipboard, so we can check for data when we write to it
    $readtext = "" ;We'll put new clipboard data in this variable

    For $i = 1 To 8 Step 1

        $rand = Random(1, 4, 1)

        Send("{CTRLDOWN}")
        ;Try various methods until we get text on the clipboard
        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() ;Any text on the clipboard?
        If $readtext <> "" Then
            Return $readtext
        EndIf

        If $i = 4 Then
            WinActivate($window_title)
            Sleep(100)
        EndIf

    Next
    Sleep(2000)
    Return $readtext

EndFunc   ;==>_GetTextFromActiveWindow

 

Edited by t0nZ

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
×
×
  • Create New...