Do something every time a window is opened?

Get help with using AutoHotkey and its commands and hotkeys
andreasf
Posts: 10
Joined: 19 Aug 2016, 06:09

Do something every time a window is opened?

21 Nov 2017, 14:49

Hello, I use this

Code: [Select all] [Download] GeSHi © Codebox Plus

WinSet, Style, -0xC00000, A


as a hotkey to hide a window's title bar. And that code is contained inside the main script that runs on my Windows all the time.

What I want is to WinSet that on a certain application every time it opens, without breaking the rest of my script functionality.

How can I do that? Thank you.
Osprey
Posts: 194
Joined: 18 Nov 2017, 05:50

Re: Do something every time a window is opened?

21 Nov 2017, 15:12

If your script currently contains only hotkeys, you can do this:

Code: [Select all] [Download] GeSHi © Codebox Plus

MyWinTitle = Untitled - Notepad

While(true)
{
WinWait, %MyWinTitle%
WinSet, Style, -0xC00000
}

If you have more than just hotkeys and can't have the script waiting for that window, you can do this and add the other commands that you need to process to the while loop:

Code: [Select all] [Download] GeSHi © Codebox Plus

MyWinTitle = Untitled - Notepad

While(true)
{
If WinExist(MyWinTitle)
WinSet, Style, -0xC00000

; Other non-hotkey things that I want to monitor while the script is running

Sleep, 1000
}
andreasf
Posts: 10
Joined: 19 Aug 2016, 06:09

Re: Do something every time a window is opened?

21 Nov 2017, 17:10

Osprey wrote:If your script currently contains only hotkeys, you can do this:

Code: [Select all] [Download] GeSHi © Codebox Plus

MyWinTitle = Untitled - Notepad

While(true)
{
WinWait, %MyWinTitle%
WinSet, Style, -0xC00000
}

If you have more than just hotkeys and can't have the script waiting for that window, you can do this and add the other commands that you need to process to the while loop:

Code: [Select all] [Download] GeSHi © Codebox Plus

MyWinTitle = Untitled - Notepad

While(true)
{
If WinExist(MyWinTitle)
WinSet, Style, -0xC00000

; Other non-hotkey things that I want to monitor while the script is running

Sleep, 1000
}


Thank you Osprey bus unfortunately this will not cut it because of the complexity of my script. I tried setting a loop but it doesn't work.. any idea why?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Osprey
Posts: 194
Joined: 18 Nov 2017, 05:50

Re: Do something every time a window is opened?

21 Nov 2017, 17:25

Your script is probably exiting when it finishes all commands because you have nothing to prevent it from doing so. Add the following to the top of your script to tell it to not exit when it reaches the end:

#Persistent

Return to “Ask For Help”

Who is online

Users browsing this forum: divanebaba and 62 guests