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
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).
Automating a process that is being run on a RDP session, I have to use ControlSend, and not Send command in AutoHotKey.
The WindowSpy doesn't find any control on the MDI toolbar, and there are no shortkey to the menu item I want to access (Filter..). How may I open the toolbar and select the item?
I've tried
ControlSend, ahk_parent, {alt}, ahk_class FNWND3170 ;Open project folder in treeview
But with no success.
I've considered using AutoIT, but I don't think that would help as the AutoIt spy doesn't pick up the control either.
Sorry, but think of the RDP window (or even full screen) as an ever-evolving bitmap image. Your PC and autohotkey have no idea what is behind the picture. Can you run the ahk script in the remote pc itself? Keep in mind, the RDP client handles your mouseclicks and keyboard (and even voice) entirely by re-directing inputs, etc. So best bet is to do a mouse click in the appropriate spot by running a script from outside the window:
CoordMode, TargetType [, RelativeTo]
Click, 44, 55 ; Clicks the left mouse button once at coordinates 44, 55 (based on CoordMode).
Use the CoordMode "RelativeTo" flag to set to "Relative" so coordinates are relative to the active window. You may have to click twice, once to activate the RDP window and then to click at the mouse position.
See https://www.autohotkey.com/docs/commands/Click.htm and https://www.autohotkey.com/docs/commands/CoordMode.htm for info.
Hth,
I have a requirement of opening my application using Ctrl + F within Windows Explorer. I think I can implement this using Auto hot key.
WinWait, Windows Explorer
{
^f::
Run "C:\myapp.exe"
return
}
But the code is not working. The code opens my application even if Windows Explorer is not open. I want Ctrl + F to be open my application only if it is active in front. I dont want to open my application even if Windows Explorer is minimized.
How can I achieve this ?
Is there any other techniques to achieve the same ?
The #IfWin directive creates context-sensitive hotkeys. Such hotkeys perform a different action depending on the type of window that is active or exists.
https://autohotkey.com/docs/commands/_IfWinActive.htm
#IfWinActive ahk_class CabinetWClass
^f::
Run "C:\myapp.exe"
return
#IfWinActive ; turn off context sensitivity
The class name of a window identifies what type of window it is.
https://autohotkey.com/docs/misc/WinTitle.htm#ahk_class
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
}
Might already be answered but here we go. I wanted to write an AutoRun script using AutoHotKey for DayZ. It basically consists of two keys being constantly pressed and then slept. Easy script. But I want it to do one more thing. I want to be able to shift tab in the standalone to the web browser and still autorun while browsing say, facebook. Is there any way this can be possibly done? Thanks in advance.
Would probably help if I pasted the script to make it more concise.
#NoEnv
SendMode Input
#IfWinActive, DayZ
lctrl::
Send {w Down}
Send {lshift Down}
W::Sleep
return
Super simple. Basically the only issue, as I said, is that when I use the steam overlay to shift + tab to the browser, my keypresses, and therefore, autorun macro, doesn't persist. I am not sure if there's any way to remedy this but any help would be appreciated.
Your keys don't persist because they depend on DayZ being active. When the steam overlay is active, well the game is no longer active.
Use ControlSend, to send keys to inactive windows.
See the following example:
#NoEnv
SendMode Input
lctrl::
ControlSend, , {w Down}, DayZ
ControlSend, , {lshift Down}, DayZ
W::Sleep
return