AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fast paste from one window to another

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
iason



Joined: 01 Nov 2005
Posts: 135

PostPosted: Sat Dec 15, 2007 12:47 pm    Post subject: Fast paste from one window to another Reply with quote

What it does: copies something from a window and pastes to another, leaving the Clipboard untouched, an the user making 2 moves in total (1 hotkey + 1 click).

For best results please assign to a hotkey of your choise.
The script was made using only AHK recources.
Probably the idea has been already implemented. Suggestions welcome as always.

Code:

SetBatchLines, 10ms

WinGetActiveTitle, ActiveWinTitle      ; Retrieve active window title

clipsaved := clipboard    ; Leave Clipboard untouched
clipboard =               ; Empty clipboard
Sleep, 100                ; Increase reliability
Send, ^c
Sleep, 100
if (!clipboard)           ; If clipboard is empty
 {
  MsgBox, Nothing has been selected/copied.
  clipboard := clipsaved    ; Restore Clipboard
  clipsaved =             ; Unblock memory
  Return
 }

Winget, AllWins, list                ; Retrieve all open windows' IDs
 Loop, %AllWins%
 {
  Wingettitle, WinTitle, % "ahk_id " AllWins%A_Index%
  WinTitle%A_Index% = %WinTitle%     ; Store win titles in array
 }

WinCount = 0
Gui Font, s8, Tahoma
Gui Margin, 9,5
Loop %AllWins%                      ; List win titles in a GUI
 {
  If WinTitle%A_Index% in ,Program Manager,%ActiveWinTitle%
   Continue                         ; Exclude no-name, Program manager and initial window
  But := WinCount + 1
  Gui Add, Text, x5 gexec, % WinTitle%A_Index%
  Gui Add, Button, w0 h0 gExec, % WinTitle%A_Index%
  WinCount++
 }

if (!WinCount)                      ; If no other window is open
 {
  MsgBox, No window exists but the one you are working on.
  clipboard = clipsaved             ; Restore Clipboard
  clipsaved =                       ; Unblock memory
  Return
 }

Gui, Show, , Quick Copy From Window to Window ...

; Resize/reposition window if too small
WinGetPos, , , WW, , Quick Copy From Window to Window ...   
if (WW<300)
 {
  sysget, Mon, Monitorworkarea
  scwidth := MonRight - MonLeft
  WinMove, Quick Copy From Window to Window ..., , (scwidth/2)-(150), , 300
 }

hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt")
OnMessage(0x200,"WM_MOUSEMOVE")

Return

; ------- END OF AUTOEXECUTE SECTION

Exec:
WinActivate, %A_GuiControl%          ; Activate target win
Send, ^v                             ; Paste on target win
clipboard := clipsaved               ; Restore Clipboard
ExitApp
Return

GuiEscape:                           ; Dismiss on 'Esc'
GuiClose:
Exitapp
Return

WM_MOUSEMOVE(wParam,lParam)          ; Function for 'hand' cursor
{
 IfWinActive, Quick Copy From Window to Window ...
  {
   Global hCurs
   MouseGetPos,,,,ctrl
   ifinstring, ctrl, Static
   DllCall("SetCursor","UInt",hCurs)
  }
 Return
}

_________________
help to be helped
Back to top
View user's profile Send private message
JDP
Guest





PostPosted: Sun Dec 16, 2007 9:43 pm    Post subject: suggestion: Reply with quote

Use ClipWait instead of sleep
Back to top
iason



Joined: 01 Nov 2005
Posts: 135

PostPosted: Mon Dec 17, 2007 8:54 am    Post subject: Re: suggestion: Reply with quote

JDP wrote:
Use ClipWait instead of sleep
Certainly a good idea. Trully that was my first venture, but i noticed that the script was not picking the copy reliably - i have no idea why...
_________________
help to be helped
Back to top
View user's profile Send private message
Laszlo



Joined: 14 Feb 2005
Posts: 4710
Location: Boulder, CO

PostPosted: Mon Dec 17, 2007 2:59 pm    Post subject: Reply with quote

Nice! To keep non-text clipboards, use
Code:
clipsaved := clipboardALL
Back to top
View user's profile Send private message
iason



Joined: 01 Nov 2005
Posts: 135

PostPosted: Thu Dec 20, 2007 6:42 pm    Post subject: Reply with quote

Laszlo wrote:
Code:
clipsaved := clipboardALL
Thanks! I missed that...
_________________
help to be helped
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group