Creating a simple script and launching it

Get help with using AutoHotkey and its commands and hotkeys
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Creating a simple script and launching it

09 Oct 2015, 01:44

I have no experience with AutoHotKey. I've read all the help, tutorials and forum posts I could in the span of about two hours and still haven't figured out how to do this. Can I please get help with this? It's simple-stupid stuff for any experienced user.

I'm running Windows 7.

I want to create a script to do the following:

Input: Ctrl-LeftMouseClick
Result: LeftMouseClick (at the cursor), Alt-Tab (to switch to the previous window), Ctrl-W

So, what I need is the following, please:

1. The text file to run that, and where to put it.

2. The version of AutoHotKey to install, and where to put it.

3. Knowing what I have to do, if anything, to have AutoHotKey running and ready to implement that macro when invoked.

Thanks so much!
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: Creating a simple script and launching it

09 Oct 2015, 02:26

0. Install AHK from this website, just do automatic install for simplicity sake.
1. open a new text document and copy this code to it:

Code: Select all

$^LButton::
Sendinput, {lbutton}{alt down}{tab}{alt up}{ctrl down}w{ctrl up}
Return
click on the drop down menu for the file type and select "all file types" then add ".ahk" to the end of the file name and save it on your desktop.
2. See step "0" above
3. Double click on the script that you have saved on your desktop. You should see a AHK icon near the clock on the taskbar. The script is now running and you can use the above hotkey.
lexikos
Posts: 6657
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Creating a simple script and launching it

09 Oct 2015, 02:53

Note that code boxes have a "Download" link which you can use instead of copy-pasting into Notepad. I have edited T_Lube's post to include the appropriate filename extension (".ahk" rather than the default ".txt").

This is equivalent to T_Lube's script:

Code: Select all

$^LButton::SendInput, {LButton}!{Tab}^w
! and ^ are Alt and Ctrl, and are applied only to the following character/{key}. See Send.
[...] return serves to finish the hotkey. However, if a hotkey needs to execute only a single line, that line can be listed to the right of the double-colon. In other words, the return is implicit
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: Creating a simple script and launching it

10 Oct 2015, 02:07

thx lexikos I figured it would be best to give him the long version since it seems to be best practice to me in case he wants to add more functionality to a hotkey, and not having to learn the mistake the hard way, that I have seen so may others make.
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Re: Creating a simple script and launching it

11 Oct 2015, 22:26

Great! It's working! One more thing is needed now, though, please.

It's intended to launch a link that opens a window that automatically opens a second window (independently of AutoHotKey), switch to the window it first opened, and close it. The problem I'm having, though, is that the first window isn't opening fast enough to be recognized (so it's closing the original window that contains the link it's initially launching).

To be specific, the link is in SmartSheet, to open a corresponding Evernote note. I run Evernote for Windows, which is local (and syncs to the web). Launching the link in SmartSheet, however, rather than just go to the appropriate note in Evernote for Windows locally, launches the web version of the Evernote note and "then" also opens it in the local Evernote for Windows. So, that web-version window is just left there, unused and useless, in front of SmartSheet, and I have to manually close it every single time.

The script is intended to close if for me and put me back to the Evernote for Windows window.

So...

Can I insert a pause between execution of the mouse click and the Alt-Tab, and have it auto-resume after the second window has opened?

Thanks very much!
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Creating a simple script and launching it

12 Oct 2015, 15:06

Here is one method using WinExist. To try it out, just replace EverNoteTitle with the window title of the EverNote window you want it to wait for...

Code: Select all

$^LButton::
SendInput, {LButton}
While !WinExist("EverNoteTitle")
    Sleep 10
SendInput, !{Tab}^w
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Re: Creating a simple script and launching it

16 Oct 2015, 03:15

I don't quite understand the nuances or quirks of what's going on with how SmartSheet's launching of the web version of the Evernote note in a browser is then leading to it (which I believe is Evernote at that point) looking for a local Evernote for Windows installation and launching that, but it seems that somehow that process is confusing Windows as to what had the focus immediately prior to the Evernote for Windows window that opens last.

The reason I say there are quirks confusing the system is that the scripts you've been giving me here are still not working. It doesn't close the window I want it to close, apparently because the Alt-Tab is not returning the focus to the Evernote browser window that opens second-to-last, immediately before Evernote for Windows. It's strange because a manual Alt-Tab returns the focus to that Evernote browser window, and following it with a manual Ctrl-W closes the Evernote browser window just fine.

For what it's worth, I had someone from ActiveWords walk me through creating a macro with their software and that works perfectly fine. The only downside to it is that it's a bit more manual work typing a command string each time I want to implement it, compared to how efficient using Ctrl-mouseclick with AutoHotKey would be.

Any chance I can pay someone here to remote into my system and see if we can make it work with AutoHotKey?

Thanks!

Jay
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Creating a simple script and launching it

16 Oct 2015, 08:23

Before you actually hire anyone to remote in and do it for you...
AutoHotkey comes with a utility called Window Spy. If you run that (easiest way is just right-click the AutoHotkey tray icon and select Window Spy) while both of your EverNote windows are open, does it show a difference between the two windows? If it does, then we can make AutoHotkey close the correct window without having to rely on Alt+Tab.

If Window Spy does not show a difference, then perhaps you could do something like this....

Code: Select all

$^LButton::
SendInput, {LButton}
While !WinExist("EverNoteTitle")
    Sleep 10
Send YourActiveWordsCommandStringHere
Return
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Re: Creating a simple script and launching it

17 Oct 2015, 03:04

I hugely appreciate the help.

I assume for "EverNoteTitle" I want what's in the title bar for Evernote for Windows, which is "All Notebooks - [my-email-address] - Evernote".

The code in the post directly above is behaving erratically, producing three or four different results -- and I think once it did what we wanted.

Using the stand-alone ActiveWords approach at least gives me an easy way to have three variations, leaving me either in Evernote, at the SmartSheet dialog box for launching other links, or back in the main SmartSheet screen. And since I have an X-Keys 24 to the left of my keyboard, I can program three keys for those variations. (I'm not entirely thrilled with ActiveWords because of the frequency with which it makes things happen that are not intended, but I'm assuming I'll learn to work with that.)

It would still be nice to be able to make this behave as I'd like using just AutoHotKey, or else, as you suggested, having AutoHotKey invoke the ActiveWords string.

Here's what Window Spy shows me:

Evernote for Windows window:
---
All Notebooks - [my-email-address] - Evernote
ahk_class ENMainFrame
ahk_exe Evernote.exe

Browser window with Evernote web-based note:
---
12343 - Google Chrome
ahk_class Chrome_WidgetWin_1
ahk_exe chrome.exe

... where 12343 is the title of the given note.

Thanks again!
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Re: Creating a simple script and launching it

17 Oct 2015, 03:07

Shadowpheonix wrote:Here is one method using WinExist. To try it out, just replace EverNoteTitle with the window title of the EverNote window you want it to wait for...

Code: Select all

$^LButton::
SendInput, {LButton}
While !WinExist("EverNoteTitle")
    Sleep 10
SendInput, !{Tab}^w
By the way, assuming I'm correct in the post directly above as to what I should enter for "EverNoteTitle", this didn't work.
Heezea
Posts: 53
Joined: 30 Sep 2013, 21:33

Re: Creating a simple script and launching it

18 Oct 2015, 09:52

Try the code below. You can try varying the "Sleep 100" lines. I find that often varying the delays between actions can solve issues.

Code: Select all

$^LButton::
	SendInput, {LButton}
	While !WinExist("ahk_exe Evernote.exe")
	{
		Sleep 10
	}
	Sleep 100 ;Try varying this if needed. 100 ms = 0.1 seconds, 500ms = 0.5 seconds
	SendInput, !{Tab}
	Sleep 500 ;Try varying this if needed. 100 ms = 0.1 second, 500ms = 0.5 seconds
	SendInput, ^w
return
It can also be really beneficial to use a good script editor like SciTe4AutoHotkey, see link: http://autohotkey.com/boards/viewtopic.php?f=6&t=62
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Re: Creating a simple script and launching it

18 Oct 2015, 13:38

Thanks. That still isn't working. I tried it as is, and with substantially longer sleep periods, to no avail (and it's going to remain a challenge since the speed at which those windows open varies). (At one point it launched Intel Management and Security.)

I think I need to abandon the mission and live with the other options I've managed to create thus far.

Thanks again for all the effort to help!
KeyMan1
Posts: 8
Joined: 09 Oct 2015, 01:32

Re: Creating a simple script and launching it

19 Oct 2015, 00:26

How about a different approach?

Maybe I should use AutoHotKey to do what I figured out how to accomplish with ActiveWords? Until I explore further, ActiveWords seems a bit more cumbersome overall than AutoHotKey. ActiveWords has advantages like automatically syncing to my other machines, and other things, so I don't have any idea which way I'd prefer to lean for this particular task, but why not do with AutoHotKey what I do now with ActiveWords anyway and keep my options open?

That means handling things after all the windows have opened. It also means no more issues with timing or having to name windows.

This would mean having three--- make it four things I can do with AutoHotKey at any time, depending where I want to go: leaving me either in Evernote, at the SmartSheet dialog box for launching other links, or back in the main SmartSheet screen.

1. Close the Evernote web-browser window and the SmartSheet dialog box, and return me to Evernote:
Alt-Tab Ctrl-W Alt-Tab Esc Alt-Tab

2. Close the Evernote web-browser window and leave me at the SmartSheet dialog box:
Alt-Tab Ctrl-W Alt-Tab

3. Close the Evernote web-browser window and the SmartSheet dialog box, and leave me in SmartSheet:
Alt-Tab Ctrl-W Alt-Tab Esc

4. Close the Evernote web-browser window, and return me to Evernote (leaving the SmartSheet dialog box open):
Alt-Tab Ctrl-W

Can I please see how to do that?

I'm not sure what to use for key combinations. I'm open to suggestions. (Right now, in ActiveWords, I use "ene", "end", and "ens" for ending up in Evernote, Dialog box, or SmartSheet. Actually, I'll probably implement X-Keys 24 macros for it anyway.)

Thanks again, so very much!

Jay
Heezea
Posts: 53
Joined: 30 Sep 2013, 21:33

Re: Creating a simple script and launching it

19 Oct 2015, 08:11

Jay, you've learned a lot about how to get AHK running. It's really an amazing program that has virtually endless possibilities. I'd stick with it.

The first thing we need to figure out is why these basic key combinations are not giving you good results. AHK should be simulating what you're achieving with key presses pretty easily. One thing is that some programs like certain kinds of "send" better than others. There are three main ones. 1. SendInput (typically the most useful, what we've been using in your case) 2. Send, and 3. SendInput. Also, remember, ! = Alt or use {Alt}; ^ = Ctrl or use {Ctrl}, + = Shift or use {Shift} Try replacing the SendInput commands with just Send. If that doesn't work, try replacing ! with {Alt} and ^ with {Ctrl}. Try to be specific about where things are going wrong; are you alt-tabbing correctly, but not closing the window? Is anything going right?

As for the other requested features, see below. You can choose any key combination you'd like.

Code: Select all

#SingleInstance Force

;1. Press F1 to perform: Alt-Tab, Ctrl-w, Alt-tab, Esc, Alt-Tab
F1::
	Send, !{Tab}
	Sleep 100
	SendInput, ^w
	Sleep 100
	Send, !{Tab}
	Sleep 100
	Send, {Esc}
	Sleep 100
	Send, !{Tab}
	Sleep 100
return

;1a Same as above, but alternate - Press Alt-F1
!F1::
	Send, {Alt}{Tab}
	Sleep 100
	Send, {Ctrl}w
	Sleep 100
	Send, {Alt}{Tab}
	Sleep 100
	Send, {Esc}
	Sleep 100
	Send, {Alt}{Tab}
	Sleep 100
return

;2. Press F2 to perform: Alt-Tab, Ctrl-w, Alt-Tab
F2::
	Send, !{Tab}
	Sleep 100
	SendInput, ^w
	Sleep 100
	Send, !{Tab}
	Sleep 100
return

;3. Press F3 to perform: Alt-Tab, Ctrl-w, Alt-Tab, Esc
F3::
	Send, !{Tab}
	Sleep 100
	SendInput, ^w
	Sleep 100
	Send, !{Tab}
	Sleep 100
	Send, {Esc}
	Sleep 100
return

;4. Press F4 to perform: Alt-Tab, Ctrl-w
F4::
	Send, !{Tab}
	Sleep 100
	SendInput, ^w
	Sleep 100
return

Return to “Ask For Help”

Who is online

Users browsing this forum: josewilian, Pino76 and 233 guests