AutoHotKey – scripts with more than one Alt-Tab

alt-tabautohotkeyscript

I am trying to create a script that copies the fields in a form on one window to a form on another window using Alt-Tab to move between the windows.

The first alt-tab works to move from window 1 to window 2 but the next alt-tab to move from window 2 to window 1 doesn't work.

My script is as follows:

#z::Send ^c!{tab}^v!{tab}{tab}^c!{tab}{tab}^v!{tab}{tab}^c!{tab}{tab}^v!{tab}

On pressing Window z I want it to copy the current field in window 1, move to window 2 and paste it, then move back to window 1 and copy the next field, move to window 2 and paste into the next field and so on.

Can anyone help.

Thanks

Best Answer

I haven't found sending string of keystrokes to be very effective in this type of circumstance. There are too many different ways it could go wrong. I'd try to use the built in clipboard variables and only swap between windows once.

You can use a hotkey to do a set of instruction using this format in your script:

z::
; do a bunch of stuff here
return

I would grab the data from the first form all at once and store it:

clipboard =  ; Start off empty to allow ClipWait to detect 
Send ^c
ClipWait 
Field1:=ClipboardAll

Send {Tab} ; move to next field

Once you've gotten the data from the first window, you can move to the next window:

Send AltTab 

(Although a better method is WinActivate.)

On the second window, you can move down the form, inserting data from the first:

clipboard = %Field1%
Send ^v
Wait 100

Send {Tab} ; move to field 2...

See AutoHotKey's page for Clipboard Variables for reference.

Related Question