1

I have an autohotkey script that has two parts, and it seems one part is causing the other to stop working.

One part is responsible for whenever I edit the script, it reloads it on c-s.

Second part, maps LCtrl to Apps key whenever I use ConEmu.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
If WinActive("script.ahk") {
  $>^s::
    Send >^s
    Sleep, 100
    Reload
  Return
}

#IfWinActive, ahk_class VirtualConsoleClass
{
  LCtrl::AppsKey
}

If I keep the LCtrl->Apps remapping, the auto-reloading stops working.

Why?

  • The first If doesn't do anything in for the the Hotkey below it. It is a regular If. It should either be #If (you forgot the # in front of it) or you have to use #IfWinActive in both cases. – lintalist Dec 14 '15 at 22:24
  • I don't understand, your saying using a regular if is useless? I tried using the #if directive, and it yields the same results. – Daniel K. Dec 14 '15 at 22:45
  • Is the script actually still running when it "stops working"? Use #IfWinActive as directed and a #Persistent statement. There are two blocks of code in a script, auto-execute code, starting from the top, and hotkey/hotstring code, defined using hotkey definitions. It looks to me like the regular If statement would get executed immediately and then the script would exit, and using an #IfWinActive statement would not execute immediately (as desired) and the script would execute (not desired). #Persistent would keep the script in memory and only execute on matching hotkeys. – JJohnston2 Dec 15 '15 at 7:10
  • Yes, it does not exit, there's no need for persistence. – Daniel K. Dec 15 '15 at 7:11
  • As ConEmu has its own keyboard hook it may be that AutoHotkey hotkeys simply won't work - you may be better off remapping the keys you want to use in the Settings of ConEmu itself. – lintalist Dec 15 '15 at 17:32
0

Just to be sure, you did try the following using #IfWinActive for the script.ahk hotkey?

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 

#IfWinActive script.ahk
$>^s::
Send ^s
Sleep, 100
Reload
Return

#IfWinActive, ahk_class VirtualConsoleClass
LCtrl::AppsKey
0

The main reason seems to be the TitleMatchMode.

Additionally

if Winactive("script.ahk")

Will run only once, it's not that kind of an if-case If you want to conditionally enable hotkeys, put them in between #if- statements

Try this:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
SetTitleMatchMode,Slow

#IfWinActive, edit.ahk
~$>^s::
    Sleep, 100
    Reload
Return

#IfWinActive, ahk_class VirtualConsoleClass
    LCtrl::AppsKey
#If

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.