Using a script to automatically copy selected text to clipboard. Anyway to automatically paste it upon click?

Share your favorite FastKeys commands
Post Reply
alih1029
Posts: 8
Joined: Sep 3rd, ’19, 16:01

Post by alih1029 » Sep 3rd, ’19, 16:08

Code: Select all

MouseGetPos, xx
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
   Sleep 10
   GetKeyState, LButtonState, LButton, P
   if LButtonState = U  ; Button has been released.
   {
      If WinActive("Crimson Editor") and (xx < 25) ; Single Click in the Selection Area of CE
      {
         Send, ^c
         return
      }
      break
   }
   elapsed = %A_TickCount%
   elapsed -= %TimeButtonDown%
   if elapsed > 200  ; Button was held down too long, so assume it's not a double-click.
   {
      MouseGetPos x0, y0            ; save start mouse position
      Loop
   {
     Sleep 20                    ; yield time to others
     GetKeyState keystate, LButton
     IfEqual keystate, U, {
       MouseGetPos x, y          ; position when button released
       break
     }
   }
   if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
   {                             ; mouse has moved
      clip0 := ClipBoardAll      ; save old clipboard
      ;ClipBoard =
      Send ^c                    ; selection -> clipboard
      ClipWait 1, 1              ; restore clipboard if no data
      IfEqual ClipBoard,, SetEnv ClipBoard, %clip0%
   }
      return
   }
}
; Otherwise, button was released quickly enough.  Wait to see if it's a double-click:
TimeButtonUp = %A_TickCount%
Loop
{
   Sleep 10
   GetKeyState, LButtonState, LButton, P
   if LButtonState = D  ; Button has been pressed down again.
      break
   elapsed = %A_TickCount%
   elapsed -= %TimeButtonUp%
   if elapsed > 350  ; No click has occurred within the allowed time, so assume it's not a double-click.
      return
}

;Button pressed down again, it's at least a double-click
TimeButtonUp2 = %A_TickCount%
Loop
{
   Sleep 10
   GetKeyState, LButtonState2, LButton, P
   if LButtonState2 = U  ; Button has been released a 2nd time, let's see if it's a tripple-click.
      break
}
;Button released a 2nd time
TimeButtonUp3 = %A_TickCount%
Loop
{
   Sleep 10
   GetKeyState, LButtonState3, LButton, P
   if LButtonState3 = D  ; Button has been pressed down a 3rd time.
      break
   elapsed = %A_TickCount%
   elapsed -= %TimeButtonUp%
   if elapsed > 350  ; No click has occurred within the allowed time, so assume it's not a tripple-click.
   {  ;Double-click
      Send, ^c
      return
   }
}
;Tripple-click:
   Sleep, 100
   Send, ^c
return
Using this script, works really well and copies highlighted text upon mouse click. Was wondering if there was a way to modify this and also paste it contents upon clicking into a different space (window).
User avatar
Tom
Posts: 315
Joined: Nov 24th, ’15, 23:39

Post by Tom » Sep 4th, ’19, 11:09

To paste the clipboard, just create another shortcut with the following code:

Code: Select all

Send, ^v
Post Reply