copy paste on windows as in linux, select then middle click

Post your working scripts, libraries and tools.
reupdereut
Posts: 2
Joined: 06 May 2024, 02:58

copy paste on windows as in linux, select then middle click

06 May 2024, 03:26

Hello all

first, most of this work does not belong to me, I was using a beautiful script that was from V1.x of autohotkey and could not run it on V2.x

the goal is to replicate the way one of the clipboard is handle in linux.
for those that don't use linux, let me explain :
there is multiple clipboard in linux, 2 are mostly used, one is when you select something, then use Ctrl-C to copy and Ctrl-V to paste, same as in windows.
there is another clipboard that is much more efficient, that I for one use all the time.
simple, select something withe mouse, no need to use Ctrl-C, it is copied in this second clipboard automatically.
use the middle mouse to paste, no need for a keyboard either.
both of those clipboard are independent from each other.

Windows has only the first clipboard (to my knowledge), but with Autohotkey, it is possible to implement the shortcut of the second one, select with the mouse will copy, middle click will paste.

this script is made of 3 parts, one to respond to double or triple click to select/copy, one to respond to dragging the mouse to select/copy and last to respond to middle click.
first part is from EDC on reddit https://www.reddit.com/r/AutoHotkey/comments/1873mq4/double_click_copy/
second is from mikeyww on this forum viewtopic.php?style=17&t=128081
last part is from me, but it is the simplest of the 3, just a Ctrl-V when middle click :D

I left the comments that were in the scripts and even added some as I believe it is important to understand what is going on.

there is 2 commented lines at the top and one commented block towards the end, un-comment them will display a tool-tip with the content of the clipboard, useful for debugging .

Code: Select all

#Requires AutoHotkey 2.0+        ;Needs AHK v2
#SingleInstance Force            ;Run only one instance

;CoordMode "ToolTip"             ; for tooltip with clipboad content
;SetTimer tX,50                  ; for tooltip with clipboad content

~*LButton::ClickCopy(1)          ;Pass '1' to ClickCopy()
~*LButton Up::ClickCopy(-1)      ;Pass '-1' to ClickCopy()

ClickCopy(Option:=0){            ;Main Func (Default='0')
  Static Clicked:=0              ;  Remember 'Clicked' value
  Static Release:=0              ;  Remember 'Release' value
  If (Option=1){                 ;  If '1' was passed 
    Release:=0                   ;    Set 'Release' to '0'
    Clicked++                    ;    Add '1' to 'Clicked'
  }                              ;  End If block
  If (Option=-1){                ;  If '-1' was passed
    Release:=1                   ;    Set 'Release' to '1'
    SetTimer(%A_ThisFunc%,-150)  ;    Loop Func in 150ms
  }                              ;  End If block
  If !Option                     ;  If 'Option' is '0' (Loop)
  && Release{                    ;    AND 'Release' is '1'
    Clicked:=0                   ;    Clear 'Clicked'
    Release:=0                   ;    Clear 'Release'
  }                              ;  End If block
  If (Clicked=2)                 ;  If 'Clicked' twice
  || (Clicked=3)                 ;  OR 'Clicked' thrice
    Send("^c")                   ;    Send the Copy hotkey


;;;;;;;;;;;;;;;                  ;  block for selection by mouse dragging
else{
 Static minDist := 10
 MouseGetPos &x1, &y1
 KeyWait 'LButton'
 MouseGetPos &x2, &y2
 If Abs(x2 - x1) >= minDist || Abs(y2 - y1) >= minDist
  Send '^c'
}
;;;;;;;;;;;;;;;                  ;  end of block mouse dragging

}                                ;  End Func block




;;;;;;;;;;;;;;;;;;               ;  uncomment this block for tooltip with clipboad content
;tX(){
;  Static CB:=""
;  If (A_Clipboard!=CB)
;    ToolTip(A_Clipboard,0,A_ScreenHeight,20)
;  CB:=A_Clipboard
;}
;;;;;;;;;;;;;;;;;;               ;  end of block for tooltip with clipboad content



;;;;;;;;;;;;;;;;;;               ;  This block is for when Firefox handle the middle click
#HotIf WinActive("ahk_class MozillaWindowClass")  ; if in firefox
~MButton::                       ;  Middle button does nothing, we let Firefox handle it
{
}
#HotIf
;;;;;;;;;;;;;;;;;;               ;  end of Firefox handle the middle click



~MButton::                       ;  Middle click function
{
	Send "^{v}"                  ;  Send the Paste hotkey
}
first, the script from

Return to “Scripts and Functions (v2)”

Who is online

Users browsing this forum: No registered users and 10 guests