AutoHotkey Community

It is currently May 27th, 2012, 4:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 102 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next
Author Message
PostPosted: September 20th, 2005, 9:53 pm 
Inspired by ideas posted in 'Linux-like copy/paste with mouse' (Serenity, Laszlo) and 'Double click as hotkey?' (twwilliams, Chris), my following script will auto copy selected text to clipboard. The text can be selected by either
1)Shift + Arrow Keys (Up, Down, Left, Right),
2)Left Mouse Button, or
3)DoubleClick.

Also please check out Clipboard Recorder ( http://www.lw-works.com/ ), Very Handy!

Code:
;Auto copy clipboard
~Lshift::
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
   Sleep 10
   GetKeyState, LshiftState, Lshift, P
   if LshiftState = U  ; Button has been released.
      break
   elapsed = %A_TickCount%
   elapsed -= %TimeButtonDown%
   if elapsed > 200  ; Button was held down long enough
   {
      x0 = A_CaretX
      y0 = A_CaretY
      Loop
   {
     Sleep 20                    ; yield time to others
     GetKeyState keystate, Lshift
     IfEqual keystate, U, {
       x0 = A_CaretX
       y0 = A_CaretY
       break
     }
   }
   if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
   {                             ; Caret 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
   }
}

~LButton::
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
   Sleep 10
   GetKeyState, LButtonState, LButton, P
   if LButtonState = U  ; Button has been released.
      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.
   {
      ;MouseClick, Left
      return
   }
}
; Since above didn't return, it's a double-click:
   Sleep, 100
   Send, ^c
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 26th, 2005, 10:12 pm 
I just updated the code to add auto copy to:
1>Single click in Crimson Editor's selection area to select a single line;
2>Ctrl+A (Select All);
3>Tripple Click (Will select a sentence in Word, current line in some other apps)

Code:
;Auto copy clipboard
~Lshift::
TimeButtonDown = %A_TickCount%
; Wait for it to be released
Loop
{
   Sleep 10
   GetKeyState, LshiftState, Lshift, P
   if LshiftState = U  ; Button has been released.
      break
   elapsed = %A_TickCount%
   elapsed -= %TimeButtonDown%
   if elapsed > 200  ; Button was held down long enough
   {
      x0 = A_CaretX
      y0 = A_CaretY
      Loop
   {
     Sleep 20                    ; yield time to others
     GetKeyState keystate, Lshift
     IfEqual keystate, U, {
       x = A_CaretX
       y = A_CaretY
       break
     }
   }
   if (x-x0 > 5 or x-x0 < -5 or y-y0 > 5 or y-y0 < -5)
   {                             ; Caret 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
   }
}

~LButton::
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

~^a::Send, ^c ;Ctl+A = Select All, then Copy


Report this post
Top
  
Reply with quote  
PostPosted: September 29th, 2005, 7:02 pm 
lotus notes crash with this script working. ¿any idea?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 30th, 2005, 3:36 pm 
I don't use Lotus Notes.

Try commenting out different parts of the script to find out what caused the crash.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 17th, 2006, 3:28 pm 
Offline

Joined: August 17th, 2006, 3:26 pm
Posts: 68
hmm is there a way to replace text without feeding the clipboard with the selected text?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2006, 8:14 am 
Offline

Joined: August 14th, 2006, 11:54 am
Posts: 163
Location: CPH
I´ve tried out this concept, and I love it.... just that I would really like to have it work without the double click selection, as it interfers with my using the Classic Media Player. Would it be possible to cut out the "double click" part of the script, and how to go about it? :-)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2006, 11:22 am 
Offline

Joined: August 8th, 2006, 3:55 pm
Posts: 49
@CarloI:
Quote:
I would really like to have it work without the double click selection
In both versions of pwy delete the part beginning with (up to the end)
Code:
; Otherwise, button was released quickly enough.  Wait to see if it's a double-click:
Then you have no Double Click, Tripple Click, Ctrl+A
If you are missing the Ctrl+A Hotkey, add at the end
Code:
~^a::Send, ^c


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2006, 11:36 am 
Offline

Joined: August 14th, 2006, 11:54 am
Posts: 163
Location: CPH
Robiandi "You're The Man" now it's perfect, you saved me hours of "tinkering" and thanks for thinking of how to include the "ctrl a" option again.
I´m most grateful. :-)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 24th, 2006, 2:37 pm 
Offline

Joined: August 8th, 2006, 3:55 pm
Posts: 49
@CarloI: :D :D :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 12th, 2007, 12:21 pm 
Offline

Joined: October 5th, 2006, 8:45 am
Posts: 476
@pwy

one of the most brilliant scripts!!!

thanks in advance for this!!!

just some questions:

1) does it use a second clipboard? not the windowsxp default? or the default clipboard? if it uses the default, so wont it replace the data I have copied to my clipboard by ctrl+c?

the best would be to store the selected text inside a second clipboard and not to interfere with the ctrl+c data

then to use the selected text, it would be best to have a seperate key, other than ctrl+v

the ctrl+v key should paste only the data that has been selected by ctrl+c

do you find my suggestion useful? or I miss something?

2) it doesnt seem to work well in opera, does anyone confirm? does it work with website text or only with text editor text ? (the first is only displayed text and the second text is editable text)

3) can I store multiple entries in the "second clipboard" and somehow choose which one to paste? something like multiple clipboard[/b]

4) can you make the "select by single clicking on the "line numbers" area to work in all editors? not just crimson editor?

5) there is also a problem, the script sometimes deletes the selected text and replaces it with c! I suppose the script sends ctrl+c after the selection, is there any other way to store the selected text?

6) another bug is that when I double click a desktop shortcut to open eg a file, it opens it and it drops it in the background (disabling the script returns to the default behaviour, where it opens it in the foreground) - it seems the script interferes in ALL double clicks and not in the SPECIFIC double clicks that occur over text, is there any way to fix this?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 1:41 pm 
Offline

Joined: October 5th, 2006, 8:45 am
Posts: 476
anyone please ????


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 4:55 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
It is a two-year old script. AHK has changed a lot since it was posted. You can now write a more universal and shorter script. What are your requirements?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 5:42 pm 
Offline

Joined: October 5th, 2006, 8:45 am
Posts: 476
Laszlo wrote:
What are your requirements?


my requirements is what that script does plus my notes on my previous post

thanks


to sum up:

I need a script that will auto copy selected text to clipboard.
The text can be selected by either:
1)Shift + Arrow Keys (Up, Down, Left, Right),
2)Left Mouse Button, or
3)DoubleClick.
4) Single click in Crimson Editor's selection area to select a single line
5) Ctrl+A (Select All);
6) Tripple Click (Will select a sentence in Word, current line in some other apps)

plus my above post


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2007, 12:11 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
The script consists of independent parts: one handles the muse clicks, the second one handles special commands, like Ctrl-A, another part does all the Shift and Ctrl-Shift keys, which select text. Below is the first cut of the last part. When the keyboard is used to select text, a timer is re/started, which waits for the shift key to be released, when Ctrl-C is sent to the foreground application to copy the selection to the ClipBoard.
Code:
Selectors = Left.Up.Right.Down.Home.End.PgUp.PgDn ; Shifted or Ctrl-Shifted these keys select text
Loop Parse, Selectors, .
{
   HotKey  ~+%A_LoopField%, WatchShift
   HotKey ~^+%A_LoopField%, WatchShift
}
Return

WatchShift: ; Hotkey subroutine: re/start waiting for Shift-Up
   SetTimer ShiftUp, -1
Return

ShiftUp:    ; Wait until Shift is released then copy the selection to the keyboard
   KeyWait Shift
   Send ^c
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 18th, 2007, 12:31 am 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
2nd part: There is no universal way for selection, like selecting everything. Some applications use Ctrl-A, which, for example in Multi-Edit, changes the letter to the right of the cursor from lower case to capital or vice versa, but it does not select anything. Other applications select found phrases after Ctrl-F of F3, others use Shift-Ctrl-A/S/D/F/E/X for selecting characters, words, lines, etc. Therefore, you have to define hotkeys for your favorite applications, like this:
Code:
 ~^A::Send ^c

It does not change the original function of Ctrl-A, only follows it with sending Ctrl-C, to copy the newly selected text. You can precede it with some directives to allow- or forbid it in certain applications:
Code:
GroupAdd CtrlA, ahk_class OpusApp
GroupAdd CtrlA, ahk_class Notepad
#IfWinActive ahk_group CtrlA


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 102 posts ]  Go to page 1, 2, 3, 4, 5 ... 7  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group