2
votes

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.

2
Do you need quotes around Some Game Title?OneCricketeer
According to example in autohotkey.com/docs/commands/WinActive.htm no? I also tried running the example "WinMaximize ; Maximizes the Notepad window found by IfWinActive above." - but it's not maximizing the notepad window.Optimus Prime
Okay, It wasn't working because I added the "quotes" like you said, it does run the WinMaximize on Notepad when RButton is clicked without quotes. But problem is that right click doesn't work globally anywhere on the computer. Like I said, I need to make it active only while in program. E.g. in notepad.Optimus Prime
the question's solution should be placed in an answer. It's okay to answer your own question, please don't forget to accept this very answer then, otherwise ppl will consider your problem as unsolvedphil294

2 Answers

4
votes

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.

1
votes
#IfWinActive ahk_class Notepad
RButton::
    WinMaximize
    Send, Some text.{Enter}
    Return
    #If