keep LAlt in its original function Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

keep LAlt in its original function

23 Jun 2021, 12:57

I want to remap the key LAlt only in one application, and keep the key in its original function for all the other applications.

But my code fails. Hope to have your help on fixing it. Thank a lot!

Code: Select all

$LAlt:: 
  WinGet, OutputVar, ProcessName, A
  SplitPath, OutputVar,,,, OutNameNoExt

  If (OutNameNoExt = "EXCEL") {
     Send +{F2}
  }  Else {
     Send {LAlt}
  }  
return
gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: keep LAlt in its original function  Topic is solved

23 Jun 2021, 13:05

Try

Code: Select all

#IfWinActive ahk_exe EXCEL.EXE
LAlt::Send +{F2}
#If
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: keep LAlt in its original function

23 Jun 2021, 13:14

@gregster It works! Thank you!

Sorry for another question: If I want to remap the key for diffent applications, is there any better way than codes below?

Code: Select all

#IfWinActive ahk_exe Excel.exe
LAlt::a
#If

#IfWinActive ahk_exe Word.exe
LAlt::b
#If

#IfWinActive ahk_exe notepad.exe
LAlt::c
#If
gregster
Posts: 9014
Joined: 30 Sep 2013, 06:48

Re: keep LAlt in its original function

23 Jun 2021, 14:54

If the target key is always different for each application - like you show above - it should be the best way, afaik.


If you want to remap several keys per application, you don't need to wrap them separately, but you could do this:

Code: Select all

#IfWinActive ahk_exe Excel.exe
LAlt::a
F1::b
#If

#IfWinActive ahk_exe Word.exe
LAlt::b
F1::w
#If
If you want to remap a key in the same way (same target key) for several applications, you could instead use #If and the WinActive() function:

Code: Select all

#If WinActive("ahk_exe Word.exe") || WinActive("ahk_exe notepad.exe")
LAlt::b
#If
surfactant
Posts: 99
Joined: 28 Jun 2019, 01:07

Re: keep LAlt in its original function

23 Jun 2021, 22:51

@gregster Great thanks for your patient help!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb and 140 guests