Zombeaver Posted November 29, 2020 Posted November 29, 2020 Thanks for the help y'all! I ended up going with @JoeViking245's code and that's working like a champ. If anyone's curious what this looks like in practice you can see it here. This is the manual switcher. 1 1 Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 Back again. Okay, so I'm trying to work out how to do some dynamic hotkeys based on the currently active window; i.e. if CDisplayEx is active, I want them to do one thing, and if it's not I want them to do nothing/behave as they would normally. These aren't the specific keys (I'm actually going to be using Joy buttons) but I just want to get it working first before moving on to that. $z:: if WinActive, Cdisplayex { Send, - } Else { Send, z } Return $x:: if WinActive, Cdisplayex { Send, = } Else { Send, x } Return The "Else" portion of these seem to be working because they're sending z and x, but the problem is that they're still sending just z and x even when Cdisplayex is active. Quote
JoeViking245 Posted December 4, 2020 Posted December 4, 2020 (edited) Is "Cdisplayex" the Window title or the exe file_name? I think the "If WinActive" is looking for a window title and it's not directly finding it. Title (I think) need to be exact. So "Spider Man 01-01 - Cdisplayex" will not be found the same way. Anyway, so it then jumps the the Else statement. Try: $z:: if WinActive("ahk_class Cdisplayex") { Send, - } Else { Send, z } Return Or tidy things up a little..... (same result) #if WinActive("ahk_class Cdisplayex") :*:z::- Return The second you press "z", it'll instead send "-" ONLY if Cdisplayex is the active window. Otherwise a Z by any other name is still a Z. Edited December 4, 2020 by JoeViking245 Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 The window title literally does just say "Cdisplayex" that's why I went with that. I'll try this way though. Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 Yeah that's not working either. I have - set to zoom out and = set to zoom in. It's not doing either though with the hotkey. Quote
JoeViking245 Posted December 4, 2020 Posted December 4, 2020 I'll look into more in a little bit... but try putting them in squiggly brackets. Send, {-} Send, {=} Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 Okay, got it. Using ahk_exe Cdisplayex.exe instead of ahk_class Cdisplayex works. Thanks! 1 Quote
JoeViking245 Posted December 4, 2020 Posted December 4, 2020 It's [very] case sensitive. CDisplayEx #if WinActive("ahk_class CDisplayEx") :*:z::- Return Quote
JoeViking245 Posted December 4, 2020 Posted December 4, 2020 Just now, Zombeaver said: Okay, got it. Using ahk_exe Cdisplayex.exe instead of ahk_class Cdisplayex works. Thanks! That was my next guess. Glad it's working! 1 Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 Okay, so, the next question is, where exactly would I put that in the existing code? I tried putting it above the Function1 section but that didn't work (breaks the rest of it). #SingleInstance Force #WinActivateForce Gui, +AlwaysOnTop Gui, -Caption ;removes caption and border Gui, color, Black ; sets window color Gui, Add, Picture, W%A_ScreenWidth% H%A_ScreenHeight%, Gui, Show, , Blocker SetTitleMatchMode, 2 WinWait, Cdisplayex WinSet, Transparent, 0, ahk_exe CDisplayEx.exe WinWait, RetroArch VICE WinActivate, RetroArch VICE Sleep, 200 Gui, -AlwaysOnTop Gui, Hide Hotkey, ~NumpadSub & NumpadEnter, Function1 Loop { IF ProcessExist("Retroarch.exe") { IF ProcessExist("CDisplayEX.exe") {} Else { Gui, Hide run, nomousy.exe Sleep, 500 Process, Close, nomousy.exe ExitApp } } Else { Winclose, Cdisplayex Gui, Hide run, nomousy.exe Sleep, 500 Process, Close, nomousy.exe ExitApp } Sleep, 1500 } ProcessExist(Name){ Process,Exist,%Name% return Errorlevel } Return Function1: run, nomousy.exe /hide Gui, Show, , Blocker SetTitleMatchMode, 2 WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe WinActivate, Cdisplayex WinSet, Transparent, 0, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 20, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 40, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 60, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 80, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 100, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 120, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 140, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 160, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 180, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 200, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 220, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 240, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, Off, ahk_exe CDisplayEx.exe Gui, Hide Hotkey, ~NumpadSub & NumpadEnter, Function2 Gui, Show, NA, Blocker WinSet, AlwaysOnTop, Off, ahk_exe CDisplayEx.exe Return Function2: SetTitleMatchMode, 2 WinSet, Transparent, 240, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 220, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 200, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 180, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 160, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 140, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 120, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 100, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 80, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 60, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 40, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 20, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 0, ahk_exe CDisplayEx.exe Gui +AlwaysOnTop Sleep, 250 WinActivate, RetroArch VICE Sleep, 250 WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe Gui -AlwaysOnTop Gui, Hide run, nomousy.exe Hotkey, ~NumpadSub & NumpadEnter, Function1 Return Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 I also tried this but that didn't work either. Spoiler #SingleInstance Force #WinActivateForce Gui, +AlwaysOnTop Gui, -Caption ;removes caption and border Gui, color, Black ; sets window color Gui, Add, Picture, W%A_ScreenWidth% H%A_ScreenHeight%, Gui, Show, , Blocker SetTitleMatchMode, 2 WinWait, Cdisplayex WinSet, Transparent, 0, ahk_exe CDisplayEx.exe WinWait, RetroArch VICE WinActivate, RetroArch VICE Sleep, 200 Gui, -AlwaysOnTop Gui, Hide Hotkey, ~NumpadSub & NumpadEnter, Function1 Loop { IF ProcessExist("Retroarch.exe") { IF ProcessExist("CDisplayEX.exe") {} Else { Gui, Hide run, nomousy.exe Sleep, 500 Process, Close, nomousy.exe ExitApp } } Else { Winclose, Cdisplayex Gui, Hide run, nomousy.exe Sleep, 500 Process, Close, nomousy.exe ExitApp } Sleep, 1500 } ProcessExist(Name){ Process,Exist,%Name% return Errorlevel } Return Loop { #if WinActive("ahk_exe Cdisplayex.exe") :*:z::- Return #if WinActive("ahk_exe Cdisplayex.exe") :*:x::= Return } Return Function1: run, nomousy.exe /hide Gui, Show, , Blocker SetTitleMatchMode, 2 WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe WinActivate, Cdisplayex WinSet, Transparent, 0, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 20, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 40, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 60, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 80, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 100, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 120, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 140, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 160, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 180, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 200, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 220, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 240, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, Off, ahk_exe CDisplayEx.exe Gui, Hide Hotkey, ~NumpadSub & NumpadEnter, Function2 Gui, Show, NA, Blocker WinSet, AlwaysOnTop, Off, ahk_exe CDisplayEx.exe Return Function2: SetTitleMatchMode, 2 WinSet, Transparent, 240, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 220, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 200, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 180, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 160, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 140, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 120, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 100, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 80, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 60, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 40, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 20, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 0, ahk_exe CDisplayEx.exe Gui +AlwaysOnTop Sleep, 250 WinActivate, RetroArch VICE Sleep, 250 WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe Gui -AlwaysOnTop Gui, Hide run, nomousy.exe Hotkey, ~NumpadSub & NumpadEnter, Function1 Return Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 Worst case scenario I can bake it into other scripts that I'm running in parallel anyway, but I would prefer to keep it all self-contained if possible (which it seems like it should be). Quote
JoeViking245 Posted December 4, 2020 Posted December 4, 2020 It doesn't need to be in a loop. The # tells it to make the hotkey always available/checked. Also get rid of the last "Return" at the same time you get rid of the loop. I've never done an extensive script like this with hotkeys in it. So I don't know if it's ok to put it after the other [awesome looking] loop that checks when 1 or the other programs close. To be safe, I'd say put before. But ya, take it out of its' loop. ;Loop ;{ #if WinActive("ahk_exe Cdisplayex.exe") :*:z::- Return #if WinActive("ahk_exe Cdisplayex.exe") :*:x::= Return ;} ;Return Can probably even throw them in at the top right after #WinActivateForce. Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 I think I actually tried that, honestly. I tried the loop after not using one didn't work. We'll see. Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 Yeah, that does not work. That borks the whole rest of the script. Quote
jayjay Posted December 4, 2020 Posted December 4, 2020 1 hour ago, JoeViking245 said: ;Loop ;{ #if WinActive("ahk_exe Cdisplayex.exe") :*:z::- Return #if WinActive("ahk_exe Cdisplayex.exe") :*:x::= Return ;} ;Return If you put this at the top of the script and you have "return" then whatever is after the return wont get executed? Long time since I played with ahk. Cant you just: $z:: if WinActive("ahk_exe Cdisplayex.exe") //might need to check the quotes are correct { Send, - msgbox "im sending -" //check to see if button press is working } Else { Send, z msgbox "im sending z" } Return At the bottom of script? Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 If I put it at the top, the blocker, the watchdog loop, etc. don't start correctly, and the hotkey to swap to CDisplayEx doesn't work. If I put it above Function1 the hotkey to swap to CDisplayEx doesn't work correctly. If I put it in Function 1 above the swap hotkey, the hotkey to swap to CDisplayEx doesn't work correctly. If I put it at the bottom the hotkey to swap to CDisplayEx doesn't work correctly. Quote
Zombeaver Posted December 4, 2020 Posted December 4, 2020 I'm not having any luck putting it anywhere. It's essentially blocking everything that comes after it and stopping the other hotkeys from functioning no matter where it's located. If I put it in a completely separate script running alongside it's fine. I feel like there should be a way to make it work in the same script though. I simplified it even further to: #if WinActive("ahk_exe Cdisplayex.exe") :*:z::- :*:x::= Return Quote
jayjay Posted December 4, 2020 Posted December 4, 2020 Could try putting loop in a timer and use getkeystate: #Persistent #SingleInstance Force #WinActivateForce Gui, +AlwaysOnTop Gui, -Caption ;removes caption and border Gui, color, Black ; sets window color Gui, Add, Picture, W%A_ScreenWidth% H%A_ScreenHeight%, Gui, Show, , Blocker SetTitleMatchMode, 2 WinWait, Cdisplayex WinSet, Transparent, 0, ahk_exe CDisplayEx.exe WinWait, RetroArch VICE WinActivate, RetroArch VICE Sleep, 200 Gui, -AlwaysOnTop Gui, Hide Hotkey, ~NumpadSub & NumpadEnter, Function1 SetTimer, MyFunction, 1000 ;put previous loop in timer, bottom of script Loop { KeyIsDown := GetKeyState("z") if (KeyIsDown == 0) ;key not down { } else ;key is down { if WinActive("ahk_exe Cdisplayex.exe") { Send, - msgbox "im sending -" } else { Send, z msgbox "im sending z" } KeyWait z } } ProcessExist(Name){ Process,Exist,%Name% return Errorlevel } Return Function1: run, nomousy.exe /hide Gui, Show, , Blocker SetTitleMatchMode, 2 WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe WinActivate, Cdisplayex WinSet, Transparent, 0, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 20, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 40, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 60, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 80, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 100, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 120, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 140, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 160, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 180, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 200, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 220, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 240, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, Off, ahk_exe CDisplayEx.exe Gui, Hide Hotkey, ~NumpadSub & NumpadEnter, Function2 Gui, Show, NA, Blocker WinSet, AlwaysOnTop, Off, ahk_exe CDisplayEx.exe Return Function2: SetTitleMatchMode, 2 WinSet, Transparent, 240, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 220, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 200, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 180, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 160, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 140, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 120, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 100, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 80, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 60, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 40, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 20, ahk_exe CDisplayEx.exe Sleep, 10 WinSet, Transparent, 0, ahk_exe CDisplayEx.exe Gui +AlwaysOnTop Sleep, 250 WinActivate, RetroArch VICE Sleep, 250 WinSet, AlwaysOnTop, On, ahk_exe CDisplayEx.exe Gui -AlwaysOnTop Gui, Hide run, nomousy.exe Hotkey, ~NumpadSub & NumpadEnter, Function1 Return MyFunction: { IF ProcessExist("Retroarch.exe") { IF ProcessExist("CDisplayEX.exe") {} Else { Gui, Hide run, nomousy.exe Sleep, 500 Process, Close, nomousy.exe ExitApp } } Else { Winclose, Cdisplayex Gui, Hide run, nomousy.exe Sleep, 500 Process, Close, nomousy.exe ExitApp } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.