I'm using WinActivate but I'm having problems with the macro stalling when I have the window minimized before I run the macro. The macro will continue if I manually perform the next step in the macro. The macro runs normally if the window is not minimized before I start the macro. I noticed that if the macro starts out minimized, WinActivate will bring up the window but the window will not be active. I have tried WinRestore but it doesn't work. I have tried to have the macro click on the window after WinActivate but the window does not become active and stalls until I manually complete the next step.
Related
I use chrome bookmarks a lot, and I also often have to send people screen snippets very often, however I don't want all my bookmarks on display (some are sorta private). I know I could add them to the Other Bookmarks folder, but would rather easy access. What I've been doing for a while is hitting the bookmark shortcut (CTRL+SHIFT+B), then the snipping tool (WIN+SHIFT+S), taking my screenshot and then putting the Bookmarks back (CTRL+SHIFT+B). Eventually I decided to bite the bullet and spend some time automating it, so that hitting CTRL+SHIFT+S would close the Bookmark Bar, and letting go of the mouse (after taking the clipping) would put it back. This is what I came up with:
~#+s:: Send, ^+B
KeyWait, LButton, D
Send, ^+B
return
Although the first half works (Bookmarks go away, snipping tools open) at no point does the bar return. I've tried many things including setting up a timer, and waiting for the space bar instead of the mouse button, which i'd only hit when ready. I have also tested, and manually pressing the keys immediately after letting go the mouse button did indeed re-open the Bookmarks.
Would anyone be able to explain why this is happening? I would really appreciate any help!
First problem is that you put the first command on the same line as the hotkey definition.
This will create a one liner hotkey and the rest of the code below wont run.
Second problem is that you're sending the input to show bookmarks again while the screenshotting window is active. You're going to want to wait until chrome is active again.
This works:
#IfWinActive, ahk_exe chrome.exe
~#+s::
SendInput, ^+b
Sleep, 2000
WinWaitActive, ahk_exe chrome.exe
SendInput, ^+b
return
#IfWinActive
A bit of sleep so the screenshot window has time to open, and also added in #IfWinActive, because I'd assume you only want that hotkey to be active while you're on chrome.
Also switched over to SendInput and made the b lower case. Having it as uppercase would send Shift+B (on most keyboard layouts).
the following simple script is for closing the window "sponsored session" after the teamviewer(remote control client) disconnected, but i found the script does actually not working ? need help, thanks very much
#Persistent
#NoEnv
WinWait Sponsored session
WinKill
To close a window with Autohotkey as soon as it pops up, we have to create a loop (to do it multiple times), wait for a window to show up and kill it then. We detect the window through its title (here: "Sponsored Session")
SetTitleMatchMode, 2
#NoEnv
Loop, {
WinWait Sponsored session
WinKill
sleep 100
}
The SetTitleMatchMode, 2 does a partial match on the window title, so it may be kill more then expected if not used with caution (e.g. it will kill an browser if the title is part of the pagetitle).
The title of the target window can easily be detected with the "Window Spy" tool, which comes with AHK and can be used via the tray menu icon of any running AHK script.
Using Loop will cause a load on the CPU. So I made it resident in #Persistent and initialized with reload after processing.
#Persistent
#SingleInstance Force
WinWait, Sponsored session{
WinActivate, Sponsored session
Sleep, 500
Send, {Enter}
reload
}
Imagine my application's window class name is classAbc
My app has a minimized in tray ability,
When a custom key is pressed it goes into tray,
How to activate it from the tray?
WinActivate, ahk_class classAbc
won't work at that time
I also tried WinShow with no success
Will it have a different class name when it goes into tray?
if so I used a macro recorder to find it's class name when it is resident in tray
but just found 2 classes which I think both are related to Microsoft windows menubar itself:
The classes and the activation codes:
WinActivate, ahk_class Shell_TrayWnd
WinActivate, ahk_class NotifyIconOverflowWindow
Tried these also but my app doesn't appeared once it goes to the tray.
Thanks in advance for any help
There are two methods depending on how your application manages its minimizing to tray:
WinShow ahk_class YOUR_APP_WINDOW_CLASS - to get the main window class name use AHK's built-in Window Spy available from a tray menu of an AHK script or in Windows Start Menu.
If the above method stops working on subsequent runs then the application stores its minimization state internally and you'll have to use TrayIcons function to send a mouse click message to the tray icon.
Since the application that is in the tray is just hidden (usually), you should use DetectHiddenWindows first. Then you use WinActivate
So it will look like this
#NoEn ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
DetectHiddenWindows, On
WinActivate, ahk_class classAbc
PS. I don't know what you want to do after activating the app from tray, but it might be a good idea to use WinWaitActive before anything else
I have a very simple AutoHotkey.ahk file, where I remap Capslock to Esc and Esc to Capslock (swapping the keys):
Capslock::Esc
Esc::Capslock
However, this doesn't work in games like Battlefield 4 or League of Legends. It simply does not do anything.
However, I can press Reload This Script in AutoHotkey, and the remapping will start working in those games. It does however work in other games without the need to reload the script first.
I hope you can help me. I would really like this to just work, instead of manually reloading the script.
Try using the #IfWinActive directive so that those hotkeys only work in the programs you want - then you don't need to ever reload.
Check in the documentation for "Context-sensitive hotkeys" (under "hotkey" in the index). Here is an example from the documentation:
#IfWinActive, ahk_class Notepad ^a::MsgBox You pressed Ctrl-A while Notepad is active. Pressing Ctrl-A in any other window will pass the
Ctrl-A keystroke to that window.
#c::MsgBox You pressed Win-C while Notepad is active.
But I think I know why it begins to "not work". It may be that certain programs set those keys as hotkeys. Whenever you start those programs they set their own hotkeys and it overrides your script. You see, the hotkey combination belongs to whatever program sets it last. When you reload the script, it resets your script as having the authourity.
So if you want the script to never be overridden, and you don't want to manually reload it, find out what programs the combinations don't work in, and use ifwinactive to reload your script using autohotkey's reload command.
I have made an AHK script that will take file names from an Excel spreadsheet, open the file in a different program, then export that file to two different formats.
It's working pretty well, except sometimes, the file has some little tweak that needs to be done with it (wrong orientation, hidden layers, etc) that create a popup.
I've tried to program around that by using ifwinexist conditions, so that if I know when a window is SUPPOSED to pop up, the script can deal with it.
The problem I have is that the popup windows can happen at times that I do NOT expect.
So, is there a way to run a thread until the window pops up, closes the window, but then will continue to look for the window?
Thank you
You are looking for SetTimer, which spawns another thread. The following code checks for the window with partial name Notepad every second (1000ms), and closes it if found.
SetTitleMatchMode, 2
SetTimer, CheckWin, 1000
CheckWin:
IfWinExist, Notepad
WinClose, Notepad
Return