Different hotkeys for different winactives in one script Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
flacito
Posts: 44
Joined: 06 Oct 2019, 11:43

Different hotkeys for different winactives in one script

Post by flacito » 20 May 2022, 07:15

How to use same hotkeys for different windows, but for each window they have their own function in one script?
Using identical hotkeys for different windows does work when I save the script as different files, but this is ineffective as I would have to save multiple files. I want one file, same hotkeys but different functions for each window.

The script I'm using now have been revised many times, and I have tried different methods but none work. The problem is that the script works just as it would without it. My latest version is below.
For instance, the hotkeys in sublime text also work in explorer.exe, while I only want it to work in sublime text.

Code: Select all

#If WinActive ("ahk_exe sublime_text.exe")
ins::{
home::}

#If WinActive("ahk_exe Explorer.EXE")
!1::send, {enter}
!2::SendInput, {f2}
!3::SendInput, !{left}
f1::send, {enter}

#If WinActive("ahk_exe dopus.exe")
!1::send, {enter}
!2::SendInput, !{left}
!3::SendInput, !{right}
f1::send, {enter}


#If WinActive("ahk_exe Everything.exe")
!1::send, {enter}
f1::send, {enter}
\:: Send, {down}
]::Send, {up}

#If

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Different hotkeys for different winactives in one script  Topic is solved

Post by BoBo » 20 May 2022, 08:21

Code: Select all

#If WinActive("ahk_exe sublime_text.exe")
ins::{
home::}
#If

#If WinActive("ahk_exe Explorer.EXE")
!1::send, {enter}
!2::SendInput, {f2}
!3::SendInput, !{left}
f1::send, {enter}
#If

#If WinActive("ahk_exe dopus.exe")
!1::send, {enter}
!2::SendInput, !{left}
!3::SendInput, !{right}
f1::send, {enter}
#If


#If WinActive("ahk_exe Everything.exe")
!1::send, {enter}
f1::send, {enter}
\:: Send, {down}
]::Send, {up}
#If
Will this do it?

Edit. Removed redundant space character from initial WinActive()-function.

flacito
Posts: 44
Joined: 06 Oct 2019, 11:43

Re: Different hotkeys for different winactives in one script

Post by flacito » 20 May 2022, 09:36

BoBo wrote:
20 May 2022, 08:21

Code: Select all

#If WinActive ("ahk_exe sublime_text.exe")
ins::{
home::}
#If

#If WinActive("ahk_exe Explorer.EXE")
!1::send, {enter}
!2::SendInput, {f2}
!3::SendInput, !{left}
f1::send, {enter}
#If

#If WinActive("ahk_exe dopus.exe")
!1::send, {enter}
!2::SendInput, !{left}
!3::SendInput, !{right}
f1::send, {enter}
#If


#If WinActive("ahk_exe Everything.exe")
!1::send, {enter}
f1::send, {enter}
\:: Send, {down}
]::Send, {up}
#If
Will this do it?
Thanks for helping! Unfortunately, that doesn't work. I tried adding #If after every #IfWinactive, but that didn't work. I tried it again right now just to be sure, and it doesn't help

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Different hotkeys for different winactives in one script

Post by BoBo » 20 May 2022, 09:42

There's a redundant space character in your first WinActiveSpace()-function call. Why? :think:

flacito
Posts: 44
Joined: 06 Oct 2019, 11:43

Re: Different hotkeys for different winactives in one script

Post by flacito » 20 May 2022, 09:48

BoBo wrote:
20 May 2022, 09:42
There's a redundant space character in your first WinActiveSpace()-function call. Why? :think:
(
:lol: I noticed that too, highly frustrating. It isn't there anymore in the real script

flacito
Posts: 44
Joined: 06 Oct 2019, 11:43

Re: Different hotkeys for different winactives in one script

Post by flacito » 20 May 2022, 09:57

BoBo wrote:
20 May 2022, 09:42
There's a redundant space character in your first WinActiveSpace()-function call. Why? :think:
Wait a second, it works now! How is that possible?
first I added #if myself. Then I copied paste your script instead.
Now it works.

What did you do differently apart from adding #if?

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Different hotkeys for different winactives in one script

Post by BoBo » 20 May 2022, 10:28

What did you do differently apart from adding #if?
I removed that space character that I've 'adopted' with your initial code snippet without noticing it at that time. Mission accomplished. :thumbup:

Btw, you shouldn't label the thread as solved with highlighting the posting that contains the error. JM2€ents. ;)

flacito
Posts: 44
Joined: 06 Oct 2019, 11:43

Re: Different hotkeys for different winactives in one script

Post by flacito » 20 May 2022, 12:43

I guess you're right BoBo. Thanks!

Post Reply

Return to “Ask for Help (v1)”