4

Similar to the question here, I found an AutohotKey script (solution) below in order to copy highlighted text and paste it by clicking on the middle button of the mouse. However there is still a lack in the script. This script only works when I highlight a text. I am wondering how I can modify it so that it also works when I double click on a word in the text and it gets highlighted.

cos_mousedrag_treshold := 20 ; pixels


#IfWinNotActive ahk_class ConsoleWindowClass

~lButton::
  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)
  {
    wingetclass cos_class, A
    if (cos_class == "Emacs")
      sendinput !w
    else
      sendinput ^c
  }
  return

~mbutton::
  WinGetClass cos_class, A
  if (cos_class == "Emacs")
    SendInput ^y
  else
    SendInput ^v
  return

#IfWinNotActive


;; clipx
^mbutton::
  sendinput ^+{insert}
  return
6
  • After the text is highlighted, what do you want it to do? Copy automatically because you highlighted something? – Nelson Sep 30 '16 at 8:45
  • The script copies the text when I highlight it (it works perfectly till here). A word in a text can be also highlighted when you double-click on it. My problem is that when I highlight a word by double-clicking, the script won't copy it. – H'H Sep 30 '16 at 9:21
  • Yes, because it detects you highlighting something by you moving the mouse. You can't setup the script to detect highlighting by double click because it is completely indistinguishable for double clicking an icon, or any where else where double clicking occurs. – Nelson Sep 30 '16 at 9:23
  • So there is no way to completely simulate Linux mouse behavior in Windows (10)? – H'H Sep 30 '16 at 9:27
  • I don't remember Linux copying everything you double-click. – Nelson Sep 30 '16 at 9:27
7

You can modify the code like so:

~lButton::
  if (A_PriorHotKey = "~lButton" && A_TimeSincePriorHotkey < "500") {
    if (cos_class == "Emacs")
      sendinput !w
    else
      sendinput ^c
    }
  // rest of code //

Adjust 500 to higher or lower values in milliseconds if you double click faster/slower.

0

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.