Issue with short and long press and #MaxThreadsPerHotkey 2 Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Issue with short and long press and #MaxThreadsPerHotkey 2  Topic is solved

15 Dec 2018, 11:09

Hi buddies,

I faced a problem but was able to solve it by myself.
Anyway, I thought it might be useful to share it with you - in case you face the same error.

I have a script where I assign two functions to a hotkey/keycombination.
(Depending on how long the key gets pressed)
This script works perfectly:

Code: Select all

F7::
KeyWait, F7, T0.2 ; Check if key has been held for less than 200 ms
if ErrorLevel = 1 ; Script 2 (key has been held >200 ms):
{
  Send This is script 2.
  KeyWait, F7 ; Wait until key has been pressed again
}
else ; Script 1 (key has been held <200 ms):
{
  Send This is script 1.
}
return
I press F7 for less than 200 ms:
Result is:
This is script 1.
When pressing and holding the key for more than 200 ms (doesn't matter if 1 sec, 5 sec etc.), the result is:
This is script 2.


Now the problem:
When I paste this working script in my Master script, it doesn't work correctly anymore.
If I do a short key press (< 200 ms), it works.
If I do a long key press and hold the key still pressed, it pastes two lines instead of one.
Either:
This is script 2.
This is script 2.

or sometimes (if I release the key some ms after 200 ms):
This is script 2.
This is script 1.


In my master script I have several applications like:
#if WinActive("ahk_class wxWindowNR") ; Audacity


The script in this thread is for Notepad++.
Even though I don't get any error (and the key is not used anywhere), I don't understand why it doesn't work.
I also tried other keys - same result.

THE REASON:
In my Master script I had many code lines above Notepad++ a code block for CS Go.
Inside of this code block I had the line:
#MaxThreadsPerHotkey 2
(I need this line for some message timer)

Even though it has nothing to do with Notepad++ and affects completely different keys,
it had a bad effect on my Notepad++ script.

Now I moved the whole CS Go block below Notepad++.
And it works perfectly now!

So it seems even though I can split all my scripts by using

Code: Select all

#if WinActive("ahk_class Notepad++") ; Notepad++ 
#if !WinActive("ahk_group MyApplications") ; Standardprofil   
#if WinActive("ahk_class Valve001") ; Counter-Strike Global Offensive / CSGo / CS Go 
etc. it actually seems to matter in which order I placed them.
I thought most logical would be an alphabetical order.
Never expected they might affect each other.

Maybe you can tell me if there's also another solution/reason or whatever.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, mapcarter, peter_ahk, Rohwedder and 309 guests