Using the excellent AHK-v2-script-converter linked here: https://github.com/mmikeww/AHK-v2-script-converter
I was able to convert this script to run in version 2.0 of Auto Hot Key. This script enables the following:
- copy text on highlight
- copy text on double click
- paste text on middle click
Thanks to H'H for the original question/code example.
cos_mousedrag_treshold := 20 ; pixels
#HotIf !WinActive("ahk_class ConsoleWindowClass", )
~lButton::
{ ; V1toV2: Added bracket
/*
- Detects a double click and copies text after a short delay
*/
If (A_TimeSincePriorHotkey != ''){
If (A_TimeSincePriorHotkey<400) and (A_PriorHotkey="~LButton"){
Sleep 100
SendInput("^c")
return
}
}
MouseGetPos(&cos_mousedrag_x, &cos_mousedrag_y)
KeyWait("lbutton")
MouseGetPos(&cos_mousedrag_x2, &cos_mousedrag_y2)
if (abs(cos_mousedrag_x2 - cos_mousedrag_x) > cos_mousedrag_treshold
or abs(cos_mousedrag_y2 - cos_mousedrag_y) > cos_mousedrag_treshold)
{
cos_class := WinGetClass("A")
if (cos_class == "Emacs")
SendInput("!w")
else
SendInput("^c")
}
return
} ; V1toV2: Added Bracket before hotkey or Hotstring
~mbutton::
{ ; V1toV2: Added bracket
cos_class := WinGetClass("A")
if (cos_class == "Emacs")
SendInput("^y")
else
SendInput("^v")
return
} ; V1toV2: Added bracket in the end
#HotIf !WinActive(, )
;; clipx
^mbutton::
{ ; V1toV2: Added bracket
SendInput("^+{insert}")
return
} ; V1toV2: Added bracket in the end
I was not able to get double click copy suggested by Nelson to work with the included code but I fiddled for a bit and make something work. Could probably be improved.
Also, I'm noticing that my workflow is to often copy a block of text, highlight another block of text, and delete / replace it. With this script it automatically copies the second block of text (not the original text I wanted to paste). I keep looking for a solution to this, or adjust my workflow.
I'm also noticing the AHK sometimes throws errors when switching between applications, and in certain applications (like Excel), double click and click and drag cause things to behave differently then you would expect in Linux. So this script can certainly be improved be ignoring particular applications, or perhaps integrating its own clipboard.