3

I really like this feature on Linux systems. I want it too on my Windows systems, but I didn't find a proper solution.

The solutions I found:

  • True X-Mouse
  • AutoclipX
  • Autohotkey script

The problems I had with them:

  • True X-Mouse changes the mouse focus which I don't want to be active on Windows because it only messes with menus like the start menu. Also you can't close tabs with your middle mouse button if it's active.
  • AutoClipX just pastes the clipboard content and not the selected text.
  • Autohotkey script found here messes with consoles on Windows. If you are switching to your console by clicking on it it will paste a Ctrl+C which is pretty annoying.

Did anybody find a proper solution or a fix for the problems I encountered with those 3 solutions?

5
  • AFAIK you can paste the selected text by drag-and-drop to every editor or edit control (even if the window is minimized or behind another window by dragging the selected text to the window's icon on the taskbar). What is the advantage of using the middle mouse button to paste the selected text? How does it work on Linux? – user3419297 Aug 16 '18 at 14:26
  • You can select the text and switch to a different workspace or switch to a maximized window and just click middle mouse button to paste the selected text. It stays like that and only gets overwritten if you select an other text. Also you can use it to select some text from the console and paste it anywhere you want. – dun Aug 16 '18 at 14:32
  • Do you want to select the text using the middle or the left mouse button in that case? Important to know for an answer on your question. Using AHK you can select text with almost every button. – user3419297 Aug 16 '18 at 14:46
  • I want to select the text using the left mouse button. The middle mouse button is only to paste the last selected text. – dun Aug 16 '18 at 14:51
  • if you want to paste in the console then Ctrl+V/Ctrl+Shift+V is much faster, since you need to press Enter anyway. Even if you want to use the mouse then just right click on the Windows console and it'll paste – phuclv Mar 29 '20 at 10:29
2

Copy on select implementation:

Try it this way:

#NoEnv
#SingleInstance Force

mousedrag_treshold := 20 ; pixels

Hotkey mbutton, paste_selection

; #IfWinNotActive ahk_class ConsoleWindowClass

~lButton::
    MouseGetPos, mousedrag_x, mousedrag_y
    keywait lbutton, T0.3 
    If (ErrorLevel)
    {
        keywait lbutton
        mousegetpos, mousedrag_x2, mousedrag_y2
        if (abs(mousedrag_x2 - mousedrag_x) > mousedrag_treshold
        or abs(mousedrag_y2 - mousedrag_y) > mousedrag_treshold)
        {
            ; MouseGetPos,,,WindowUnderMouse
            ; WinGetClass, Class, ahk_id %WindowUnderMouse%
            ; If (Class != "ConsoleWindowClass")
                sendinput ^c
            hotkey mbutton, on
        }
    }
return

~lButton Up:: return

; #IfWinNotActive

paste_selection:
    sendinput {lbutton}
    SendInput ^v
return
3
  • Oh thank you so much. I'm going to try to adjust it but it's nearly the same as in Linux. – dun Aug 17 '18 at 6:32
  • The selected text from editors and consoles is being pasted perfectly and it doesn't send a Ctrl+C when switching to console. But it doesn't paste the selected text e.g. from the browser. Also it overrides the functionality of the middle click. You can't start a new instance of a program by clicking with the middle button on the attached programs on the taskbar or you can't close tabs or open new ones in Firefox. – dun Aug 17 '18 at 6:39
  • pressing Ctrl+V to paste on every middle click is a bad idea. What if the middle click is for moving the view port (in some apps), closing the tab or open in a new tab? – phuclv Mar 29 '20 at 10:25
1

I improved the above script a bit at the end. Just added an if statement to check if the clipboard is occupied or not and also cleared it after pasting. The other improvement is turning off the hotkey mbutton after pasting, so that it will not interfere with middle clicks for closing tabs or scrolling until some text is selected and [automatically] copied next time.

#NoEnv
#SingleInstance Force

mousedrag_threshold := 20 ; pixels

Hotkey mbutton, paste_selection

; #IfWinNotActive ahk_class ConsoleWindowClass

~lButton::
    MouseGetPos, mousedrag_x, mousedrag_y
    keywait lbutton, T0.3 
    If (ErrorLevel)
    {
        keywait lbutton
        mousegetpos, mousedrag_x2, mousedrag_y2
        if (abs(mousedrag_x2 - mousedrag_x) > mousedrag_threshold
        or abs(mousedrag_y2 - mousedrag_y) > mousedrag_threshold)
        {
            ; MouseGetPos,,,WindowUnderMouse
            ; WinGetClass, Class, ahk_id %WindowUnderMouse%
            ; If (Class != "ConsoleWindowClass")
                sendinput ^c
            hotkey mbutton, on
        }
    }
return

~lButton Up:: return

; #IfWinNotActive

The changed part:

paste_selection:

    if clipboard!=""
            {
            sendinput {lbutton}
            SendInput ^v
            Sleep, 200 ; Give some time for the text to be pasted.
            clipboard = ; clear the clipboard
            hotkey mbutton, off
            }

    return
1
  • middle click is used for a lot of purposes, so you should check if the focus is in a textbox or console instead, otherwise it'll mess up with other apps – phuclv Mar 29 '20 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.