Luis Diaz
asked on
AutoHotkey: restrict AutoHotkey and turn off them for other applications
Hello experts,
I was wondering how to restrict specific AutoHotkey for application and turn off them for other applications.
Example:
I would like to use the following AutoHotkey exclusively when I used Excel:
The benefit of If approach condition is that I restrict the AutoHotkey for Excel however the drawback is that I cannot turn off for other applications.
Let's suppose that I change the AutoHotkey for:
I would have error message instead of having the default windows action related to #d which is open desktop.
This question is crucial for my daily actions as I want to avoid clash between other default windows shortcuts.
Thank you for your help.
I was wondering how to restrict specific AutoHotkey for application and turn off them for other applications.
Example:
I would like to use the following AutoHotkey exclusively when I used Excel:
;====================================
;Excel paste special
;====================================
;$if the send contains same letters of hotstring
$^#v::
If (WinActive("ahk_exe excel.exe"))
{
Send, !esvt
Sleep, 100
Send, {Enter}
Return
}
Else
{
MsgBox,4144,Error,Active windows is not an excel windows
Return
}
The benefit of If approach condition is that I restrict the AutoHotkey for Excel however the drawback is that I cannot turn off for other applications.
Let's suppose that I change the AutoHotkey for:
;====================================
;Excel paste special
;====================================
;$if the send contains same letters of hotstring
#d::
If (WinActive("ahk_exe excel.exe"))
{
Send, !esvt
Sleep, 100
Send, {Enter}
Return
}
Else
{
MsgBox,4144,Error,Active windows is not an excel windows
Return
}
When Notepad ++ process is running. I would have error message instead of having the default windows action related to #d which is open desktop.
This question is crucial for my daily actions as I want to avoid clash between other default windows shortcuts.
Thank you for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome, Luis, happy to help. Regards, Joe
ASKER
Joe,
If I want to put double conditions, can I proceed like this:
Thank you for your help.
If I want to put double conditions, can I proceed like this:
;====================================
;Excel Fill
;====================================
#If (WinActive("ahk_exe excel.exe") or WinActive("ahk_exe WINWORD.exe"))
$#f::
Send, !hh
Sleep, 100
Return
#If ; end the context-sensitivity so it doesn't affect subsequent hotkeys/hotstrings
Thank you for your help.
> can I proceed like this
Yes. Notice this at the #If documentation (copied here under "Fair Use"):
Thus, you may proceed with the AutoHotkey code that you posted above...it will work fine! Regards, Joe
Yes. Notice this at the #If documentation (copied here under "Fair Use"):
#If [Expression]
Creates context-sensitive hotkeys and hotstrings. Such hotkeys perform a different action (or none at all) depending on the result of an expression.
Expression: Any valid expression.
Any valid expression may be used to define the context in which a hotkey should be active. For example:
#If WinActive("ahk_class Notepad") or WinActive(MyWindowTitle)
Thus, you may proceed with the AutoHotkey code that you posted above...it will work fine! Regards, Joe
ASKER
Noted, thank you very much for your feedback!
You're very welcome!
ASKER
Thank you very much for the reminder!