Jump to content
LaunchBox Community Forums

Auto Hotkey Scripts


Lordmonkus

Recommended Posts

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.

Link to comment
Share on other sites

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 by JoeViking245
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
   }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...