Please Help woth Simple Copy and Paste Script

Get help with using AutoHotkey and its commands and hotkeys
robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 31 May 2019, 10:38

I've spent the last two hours trying to figure this out and I just can't get it.

I need a simple script that presses CTRL C to copy an image that im currently viewing, then Alt Tab to switch the the previous window and CTRL V to paste a copy of that image then Atl Tab to switch back to the image.

Below is what I have and I cant seem to get it.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

^z::
Send {^c}
Send {AltTab}
Send {^v}
Send {AltTab}
Return

User avatar
Hellbent
Posts: 1061
Joined: 23 Sep 2017, 13:34

Re: Please Help woth Simple Copy and Paste Script

Post by Hellbent » 31 May 2019, 11:11

I have tried a number of times over the years to get alt+Tab to work, but it never works, no matter how I write it.
As for the point about how something is written, I don't use send very often, but I'm not sure Send,{AltTab} is a thing.
Try,

Code: Select all

Send, {Alt Down}{Tab}{Alt Up}
I have seen others say that it works for them, so maybe it will work for you. It has never worked for me though.

If sending Alt+Tab is not a route you end up being able to take, there are a few other ways that you can get the outcome you want. A simple one is to hard code swapping between two known windows. If it's basically always the same two windows, this is a simple enough process to script.

User avatar
Hellbent
Posts: 1061
Joined: 23 Sep 2017, 13:34

Re: Please Help woth Simple Copy and Paste Script

Post by Hellbent » 31 May 2019, 11:45

After some playing around I got it to work using this.

Code: Select all

*Numpad3::
	Send,^c
	ClipWait
	run C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk
	sleep,100
	send,{enter}
	sleep,100
	Send,^v
	run C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk
	sleep,100
	send,{enter}
	return
hope that helps.

thienphuongx
Posts: 2
Joined: 31 May 2019, 11:28

Re: Please Help woth Simple Copy and Paste Script

Post by thienphuongx » 31 May 2019, 11:48

Send {AltTab} not work
Why not use Send, !{Tab}
Last edited by thienphuongx on 05 Aug 2019, 16:40, edited 1 time in total.

User avatar
Hellbent
Posts: 1061
Joined: 23 Sep 2017, 13:34

Re: Please Help woth Simple Copy and Paste Script

Post by Hellbent » 31 May 2019, 11:54

thienphuongx wrote:
31 May 2019, 11:48
Send {AltTab} not work
Why not use Send, !{Tab}
Does that switch windows for you? Doesn't for me.

thienphuongx
Posts: 2
Joined: 31 May 2019, 11:28

Re: Please Help woth Simple Copy and Paste Script

Post by thienphuongx » 31 May 2019, 11:58

Hellbent wrote:
31 May 2019, 11:54
thienphuongx wrote:
31 May 2019, 11:48
Send {AltTab} not work
Why not use Send, !{Tab}
Does that switch windows for you? Doesn't for me.
I used to win 7 64 bit, And you?
Last edited by thienphuongx on 05 Aug 2019, 16:39, edited 1 time in total.

User avatar
Hellbent
Posts: 1061
Joined: 23 Sep 2017, 13:34

Re: Please Help woth Simple Copy and Paste Script

Post by Hellbent » 31 May 2019, 12:09

thienphuongx wrote:
31 May 2019, 11:58
I used to win 7 64 bit, And you?
Win 8.1 64 bit

Vaklev
Posts: 47
Joined: 04 Mar 2019, 13:58

Re: Please Help woth Simple Copy and Paste Script

Post by Vaklev » 31 May 2019, 12:26

Try this:

Code: Select all

^z::
Send {lcontrol down}c{lcontrol up}
Send {lalt down}{tab}{lalt up}
Send {lcontrol down}v{lcontrol up}
Send {lalt down}{tab}{lalt up}
Return

*Numpad3::
	Send {lcontrol down}c{lcontrol up}
	ClipWait
	run C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk
	sleep,100
	send,{enter}
	sleep,100
	Send,{lcontrol down}v{lcontrol up}
	run C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk
	sleep,100
	send,{enter}
	return
	
It will ensure your control and alt keys are firmly pressed while hitting the c and v for copy paste

Note: In case your wondering what the hell that L means, its basically the left control/alt key, you can use R for right but I think L is more practical

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 01 Jun 2019, 17:36

I tried both of the suggested scripts with no success.

I tried with my environment variables and withourt and still no good.

What should the entire txt file look like? I must be missing something.

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 02 Jun 2019, 12:04

OK, I copied this into my file exactly as shown below and it works when I hit Ctrl Z. But maybe 30% of the time it does not swap back to the image.


^z::
Send {lcontrol down}c{lcontrol up}
Send {lalt down}{tab}{lalt up}
Send {lcontrol down}v{lcontrol up}
Send {lalt down}{tab}{lalt up}
Return

*Numpad3::
Send {lcontrol down}c{lcontrol up}
ClipWait
run C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk
sleep,100
send,{enter}
sleep,100
Send,{lcontrol down}v{lcontrol up}
run C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk
sleep,100
send,{enter}
return

vsub
Posts: 476
Joined: 29 Sep 2015, 03:39

Re: Please Help woth Simple Copy and Paste Script

Post by vsub » 02 Jun 2019, 12:30

From what to what program are you trying to switch(exe name will probably be enough...and if it's not QT window,WinMenuSelectItem will probably also work)

This for example checks every time you copy something if it is image and if it is,send it to xnview without switching windows

Code: Select all

#SingleInstance,Force
#NoEnv
#Persistent
OnClipboardChange("ClipChanged")
Return


ClipChanged() {
if DllCall("IsClipboardFormatAvailable", "Uint", 2)
WinMenuSelectItem,ahk_exe xnview.exe,,Edit,Import Clipboard
}
There are manu ways to change the script to not constantly keep alt+tabing

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 03 Jun 2019, 12:26

I would be looking at an image using the windows photo viewer when I execute the script. I simply want the image im looking at to be copied to the last folder I have had open.

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 03 Jun 2019, 12:28

So what would the entire script be?

vsub
Posts: 476
Joined: 29 Sep 2015, 03:39

Re: Please Help woth Simple Copy and Paste Script

Post by vsub » 03 Jun 2019, 14:27

Well if it is that simple,why don't you just use Ctrl+S without the need of a script.
You are pressing Ctrl+Z as a hotkey,the "S" is just a tinny bit higher.

When you choose a folder once,it will always save there

~^s::
keywait,s
WinWaitActive,Save As
Send,{Enter}
Return

You can also choose where to save by using ConrolSetText but as I said,if you save manually once and choose the folder,then after that everything will be saved there

User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Please Help woth Simple Copy and Paste Script

Post by jeeswg » 03 Jun 2019, 15:16

You can get the file path by using the clipboard, as in this script:
How can you extract the full path of the photo visible in photo gallery? - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=48993&p=218126#p218126

And then use AHK's FileCopy to copy the file.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 18 Jun 2019, 12:21

I'm sorry, but I don't really understand enough about this to make use of that information. If you could provide the script that I can copy that would be much appreciated.

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 22 Jul 2019, 14:59

Anybody who can offer some help here? The script works sporadically. Probably 50% of the time it copies the file, and 25% of the time it doesn't switch back to the photo.

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 22 Jul 2019, 15:02

I like the idea of using control S to designate the save to folder, but dont know enough to complete the script.

robertdangerbyrd
Posts: 9
Joined: 31 May 2019, 10:06

Re: Please Help woth Simple Copy and Paste Script

Post by robertdangerbyrd » 30 Jul 2019, 14:52

anybody willing to assist?

vsub
Posts: 476
Joined: 29 Sep 2015, 03:39

Re: Please Help woth Simple Copy and Paste Script

Post by vsub » 31 Jul 2019, 09:13

Do you want the image to always be saved to a specific folder
Do you still want to use Ctrl+Z or it can be another hotkey

Post Reply

Return to “Ask For Help”