Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[help] #inputlevel but not overwrite key combination ?



  • Please log in to reply
7 replies to this topic
navmesh
  • Members
  • 30 posts
  • Last active:
  • Joined: 22 Apr 2013

i have 2 ahk script ,both remap "k" ,but script 1 has "scrolllock & k"

script1.ahk

k::msgbox script1
scrolllock & k::click

script2.ahk

k::msgbox script2

i want this : when running both script at the same time , if i press k ,
it will execute the script2.ahk (which show "msgbox script2" ) ,

in other way, script2 overwrite script1


so i put  #inputlevel2 in script2.ahk

it now looks like this

script1.ahk

k::msgbox script1
scrolllock & k::click

script2.ahk

#inputlevel2
k::msgbox script2

but now if i press "scrolllock & k" , it will not do the click (function of script1)
but it show msgbox (script2)
 i guess because "k" has been overwrited by script2
 and "scrolllock & k" no longer be recognized
 

i found a way to make scrolllock & k work, when i reload script1 ,and press scrolllock & k ,it will work

but if i reload script2 , i will have to reload script1 again to make that key combination work


In other way, my question is
Is it possible to overwrite "k" of script2 to "k" of script1 but still do function like "scrolllock & k" of script1 ?


Thanks



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

If you put the scrollock & k::click inside the second script, it should work. What happens when you reload script1 and press just k? Because my experience is the most-recently running script is the one that takes precedence.

 

Let's see if you even need multiple scripts to begin with. Under what context do you want to use script2's k rather than script1's k? Because if you use the script1 k for Photoshop and the script2 k for After Effects, you can do this:

 

SetTitleMatchMode, 2 ; partial title matching is accepted
#IfWinActive Photoshop
k::MsgBox Photoshop
#IfWinActive After Effects
k::MsgBox After Effects

 

#IfWinActive and SetTitleMatchMode

 

(I have no idea if After Effects is the actual name of the product, but that's just what came to memory as another product in the Adobe media editing suite.)

 

You can probably better test this by using Notepad and Calculator as programs you're most likely to have access to.



navmesh
  • Members
  • 30 posts
  • Last active:
  • Joined: 22 Apr 2013

If you put the scrollock & k::click inside the second script, it should work. What happens when you reload script1 and press just k? Because my experience is the most-recently running script is the one that takes precedence.

 

Let's see if you even need multiple scripts to begin with. Under what context do you want to use script2's k rather than script1's k? Because if you use the script1 k for Photoshop and the script2 k for After Effects, you can do this:

SetTitleMatchMode, 2 ; partial title matching is accepted
#IfWinActive Photoshop
k::MsgBox Photoshop
#IfWinActive After Effects
k::MsgBox After Effects

#IfWinActive and SetTitleMatchMode

 

(I have no idea if After Effects is the actual name of the product, but that's just what came to memory as another product in the Adobe media editing suite.)

 

You can probably better test this by using Notepad and Calculator as programs you're most likely to have access to.

Thank you for the help , Exaskryz , i knew about #IfWinActive

and my experience is the same as yours, the most-recently loaded script is the one that takes precedence , it doesn't matter the #inputlevel is

i want to know if there is another way to remap the "k" key but not have any effect on scrolllock & k on another script

Thank you for the suggestion : "put scrollock & k in the second script" , but there is so many others remap keys i use in another script ,also i 'll change them many times ,so i think when i want to use keys in a script ,i have to reload that script i want then pressing that key

i still hope to see if there is any better way

Thanks again



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

You can try playing around with specifying different InputLevels for each of the hotkeys. I tried to, but I couldn't figure out what the pattern was. I did this in one script:

 

#InputLevel 2
k::MsgBox script1
#InputLevel 3
NumLock & k::MsgBox TestScript.ahk

 

And I could make "script1" and "TestScript.ahk" appear, but that was within the same script. But as soon as I got rid of #InputLevel 2, I could only make "script1" appear, which was unexpected to me. But maybe you can figure out a structure that would work between the two scripts...



navmesh
  • Members
  • 30 posts
  • Last active:
  • Joined: 22 Apr 2013

Thanks Exaskryz , i haven't figured out how to do yet

For summary. there is 2 main problems :

1. How to make "k::" of script2 overwrite "k::" of script1 even when script1 reloaded later

2. how to make scrolllock & k of script1 works even when script2 loaded later

 

Thanks alot



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
✓  Best Answer
#InputLevel has nothing to do with the priority of hotkeys.

AutoHotkey is not designed to cooperate between processes. You must change one or both scripts to cooperate with the other script:
#If !GetKeyState("ScrollLock")
k:: ...
... or merge the scripts.

navmesh
  • Members
  • 30 posts
  • Last active:
  • Joined: 22 Apr 2013

Thanks Lexikos, it 's clear now :)



revMARKbrown
  • Members
  • 6 posts
  • Last active: Oct 27 2015 01:15 AM
  • Joined: 23 Oct 2015

k::

{

If (state = 1)

{

send   BLA BLA BAL   

 

or

 

gosub Label:

}

Else if (state =2)

{

send BLA BAL BALA

 

or

go sub label

}

else

send Bla Bla Bla

or

go sub label

}

Return