I want to create a hotkey when ahk_class #32770 windows are active, in my case, the User Accounts window opened by typing netplwiz in the Run. But, it seems that no hotkey works.
Here's what I did:
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
SetTitleMatchMode, 2 ; A window's title can contain WinTitle anywhere inside it to be a match.
#ifwinactive
#e::Run,%A_AppData%\Microsoft\Windows\Recent
;this doesn't work for ahk_class #32770, so I make the following workaround:
#if winactive("ahk_class #32770") or winactive("ahk_exe explorer.exe")
#e::Run,%A_AppData%\Microsoft\Windows\Recent
;but neither does this work. So I made the following test:
^p::msgbox,hi
;and it doesn't work.
Did I do something wrong, or any workaround?
It should work. End/Close the context with
#if or #ifwinactive as appropriate, if you have not.
Like in
#ifwinactive ahk_class #32770
#e::Run,%A_AppData%\Microsoft\Windows\Recent
#ifwinactive
#if winactive("ahk_class #32770")
#e::Run,%A_AppData%\Microsoft\Windows\Recent
#if
Related
I would like to completely hide the title bar of Notepad. That means that (1) if I switch to existing instances of Notepad, the titles gets hided, (2) if I open new instances of Notepad, the titles gets hided.
I have used the following but it does not work. Any help to correct the code or another solution is welcomed.
#IfWinActive, ahk_class Notepad
WinSet, Style, -0xC00000, A
return
#IfWinActive
#SingleInstance force
#warn
SetTimer, HN, 2500
return
r::Reload
x::ExitApp
HN:
If WinActive("ahk_class Notepad")
WinSet, Style, -0xC00000, A
return
the above code works for me, just tested on win10
It will work Only If Someone Assigns a Hotkey to execute the job... Meaning Something Should Trigger It Somewhere like in the below example.
Note: In the Script below, Both y and z, would perform the same job.
#SingleInstance force
#warn
r::Reload
x::ExitApp
#IfWinActive, ahk_class Notepad
y::WinSet, Style, -0xC00000, A
#IfWinActive
/*or*/
#IfWinActive, ahk_class Notepad
z::
WinSet, Style, -0xC00000, A
return
#IfWinActive
Below ones too can help you further in that direction
If WinActive...
IfWinActive...
I thought this was easy but it seems not. I just want to activate File Explorer this way:
WinActivate ahk_exe Explorer.EXE
But it won't work. It seems that all others work just fine:
WinActivate ahk_exe chrome.exe ; works
WinActivate ahk_exe notepad++.exe ; works
WinActivate ahk_exe OUTLOOK.EXE ; works
I also tried
WinActivate "ahk_class CabinetWClass"
The second approach works, but you shouldn't use quotes. Try this:
WinActivate ahk_class CabinetWClass
You can also make it an expression and then you must use quotes, like this:
WinActivate % "ahk_class CabinetWClass"
I used winspy to grab an ahk_class for my autohotkey macro. Sometimes that application has 2+ ahk_classes associated with that program
Example:
HwndWrapper[program.exe;;1111-1111]
HwndWrapper[program.exe;;2222-2222]
How can I use winNotExist to simply just match both names? Or perhaps use a ||, OR etc?
E.g.
F12::
IfWinNotExist, ahk_class "HwndWrapper.+"
Run, AQ8.exe
GroupAdd, kjexplorers11, ahk_class "HwndWrapper.+" ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe AQ8.exe")
GroupActivate, kjexplorers11, r
else
WinActivate ahk_class ahk_class "HwndWrapper.+" ;you have to use WinActivatebottom if you didn't create a window group.
Return
I finally figured it out. SetTitleMatchMode, Regex.
This command affects the behavior of all windowing commands, e.g. WinExist and WinActivate
Then write some javascript-like regex statements as arguments.
The full list of window commands is on AHK site
Script, revised
F12::
SetTitleMatchMode,RegEx
IfWinNotExist, ahk_class HwndWrapper.+
Run, AQ8.exe
GroupAdd, kjexplorers11, ahk_class HwndWrapper.+ ;You have to make a new group for each application, don't use the same one for all of them!
if WinActive("ahk_exe AQ8.exe")
GroupActivate, kjexplorers11, r
else
WinActivate ahk_class ahk_class HwndWrapper.+ ;you have to use WinActivatebottom if you didn't create a window group.
Return
So now I can cycle through any application with more than 1 ahk_Class name. Example of what script does
I'm trying to use a simple script that would work only when the active window is open and when you're in that window (e.g. some windowed mode game). So the script works, but it also works outside the active window, e.g. on desktop or a browser too. I don't need that. I need it to work only in the active window I set.
The script:
RButton::rightMouseClick()
rightMouseClick(){
if WinActive("ahk_class Notepad") {
WinMaximize
Send, Some text.{Enter}
return
}
}
So, this example works when you go to Notepad and right click. But also now right click doesn't work anywhere else on the computer? It works only if you hold down shift?!
How do I make this script react/work/run only when active window is Notepad? And not work globally.
Here is my suggestion:
#If WinActive("ahk_class Notepad") ;if the window with the ahk_class "Notepad" is active
RButton:: ;this hotkey is only enabled while the above statement is true
WinMaximize ;maximize the active window
Send, Some text.{Enter} ;send some keyboard input
Return ;end of the hotkey
#If ;end of the special "#If" statement
Correct indentation alone can help a lot understanding the code.
#IfWinActive ahk_class Notepad
RButton::
WinMaximize
Send, Some text.{Enter}
Return
#If
I am trying to make a basic shortcut for windowsHome + Shift + w. If word is open, I would like to set Word as the active window and maximize Word; else, if word isn't open, I would like to open a specified word document. This script works fine running once but can't run multiple times without restarting the script. I tried adding #Persistent and a never-ending while loop but this still doesn't work. What I am doing wrong? Thank you for your help in advance! I will definitely rate you up if you help me out.
#Persistent
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#+w::
while 1
{
IfWinExist *.docx - Microsoft Word
{
WinActivate
WinMaximize
}
else
{
Run, C:\Users\myHome\Desktop\311.docx
}
}
return
This is working for me:
SendMode Input
SetWorkingDir %A_ScriptDir%
#+w::
IfWinExist ahk_class OpusApp
{
WinActivate ahk_class OpusApp
WinMaximize ahk_class OpusApp
}
else
{
Run, C:\Users\myHome\Desktop\311.docx
WinWait ahk_class OpusApp
WinActivate ahk_class OpusApp
}
return
I highly recommend using the ahk_class for this purpose.
Also, you don't need the loop, otherwise it will consistently loop after the keys are pressed, keeping the window maximized. In this example, the actions happen after the keys are pressed, but only happen once.
Also, the ahk_class OpusApp is the correct class for Microsoft Word 2010.
Let me know if you need any more help.