 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
pwy Guest
|
Posted: Tue Sep 20, 2005 9:53 pm Post subject: Auto Copy Selected Text to Clipboard |
|
|
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 |
|
|
| Back to top |
|
 |
pwy Guest
|
Posted: Mon Sep 26, 2005 10:12 pm Post subject: |
|
|
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
|
|
|
| Back to top |
|
 |
guestsp Guest
|
Posted: Thu Sep 29, 2005 7:02 pm Post subject: Auto Copy Selected Text to Clipboard |
|
|
| lotus notes crash with this script working. ¿any idea? |
|
| Back to top |
|
 |
pwy Guest
|
Posted: Fri Sep 30, 2005 3:36 pm Post subject: |
|
|
I don't use Lotus Notes.
Try commenting out different parts of the script to find out what caused the crash. |
|
| Back to top |
|
 |
Stevie
Joined: 17 Aug 2006 Posts: 34
|
Posted: Thu Aug 17, 2006 3:28 pm Post subject: |
|
|
| hmm is there a way to replace text without feeding the clipboard with the selected text? |
|
| Back to top |
|
 |
Carlol
Joined: 14 Aug 2006 Posts: 151 Location: CPH
|
Posted: Thu Aug 24, 2006 8:14 am Post subject: |
|
|
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?  |
|
| Back to top |
|
 |
robiandi
Joined: 08 Aug 2006 Posts: 50
|
Posted: Thu Aug 24, 2006 11:22 am Post subject: |
|
|
@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 |
|
| Back to top |
|
 |
Carlol
Joined: 14 Aug 2006 Posts: 151 Location: CPH
|
Posted: Thu Aug 24, 2006 11:36 am Post subject: |
|
|
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.  |
|
| Back to top |
|
 |
robiandi
Joined: 08 Aug 2006 Posts: 50
|
Posted: Thu Aug 24, 2006 2:37 pm Post subject: |
|
|
@CarloI:  |
|
| Back to top |
|
 |
user
Joined: 05 Oct 2006 Posts: 423
|
Posted: Tue Jun 12, 2007 12:21 pm Post subject: |
|
|
@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? |
|
| Back to top |
|
 |
user
Joined: 05 Oct 2006 Posts: 423
|
Posted: Sun Jun 17, 2007 1:41 pm Post subject: |
|
|
| anyone please ???? |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Sun Jun 17, 2007 4:55 pm Post subject: |
|
|
| 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? |
|
| Back to top |
|
 |
user
Joined: 05 Oct 2006 Posts: 423
|
Posted: Sun Jun 17, 2007 5:42 pm Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Mon Jun 18, 2007 12:11 am Post subject: |
|
|
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 |
|
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4015 Location: Pittsburgh
|
Posted: Mon Jun 18, 2007 12:31 am Post subject: |
|
|
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:
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 |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|