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.



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:

; do a bunch of stuff here

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

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.


Here're 2 very simple methods to do exactly the alt-multiple-tabs sequence you want. The main thing is, you can specify inside the curly brackets how many times you want a key pressed!:

1) The following uses the familiar ! for alt and let's you alt-tab 2 windows away. Naturally, you can change the '2' to whatever number you need:

Send !{TAB 2}

So your script can be modified as:

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

2) This next one let's you explicitly say when alt is pressed and when it's released. Again, {tab}{tab} is abbreviated to {tab 2}:

Send {alt down}{tab 2}{alt up}

So your script can be modified as:

#z::Send ^c!{tab}^v{alt down}{tab 2}{alt up}^c{alt down}{tab 2}{alt up}^v{alt down}{tab 2}{alt up}^c{alt down}{tab 2}{alt up}^v!{tab}

Before I looked for a solution, I also tried !{tab}{tab} that you tried; it's just that the second {tab} isn't considered to have alt accompanied.

I found the answer in the AutoHotKey Help >> Keyboard Control >> Send / SendRaw / SendInput / SendPlay / SendEvent: Send Keys & Clicks


The really easy way to do this, if the window titles are always going to have at least the same partial name (Untitled - Notepad, Document1 - Notepad, etc) is to use the WinWaitActive function. If you know that they're never going to change, then open the AU3Record.exe program (located in C:\Program Files\AutoIt3\SciTE\ScriptWriter\AU3Record.exe). Begin recording, and click back and forth between the windows a couple of times. Stop recording, and take the lines that begin with WinWaitActive and the titles of your windows in the parameters, remove anything that might change, and use those lines to switch back and forth between windows.

It's much more efficient to do it that way, because you don't have to worry about giant strings of keyboard commands (do this, alt-tab, do that, alt-tab, do this again, alt-tab, etc) to maintain while editing your script.

Also, as a side note, I would break the key sequences into smaller ones. It's just easier to manage them when there are only 2 or 3 keys in a sequence per line. If you still need it to all be run at the same time, then make it into a function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.