Keys get stuck - i need reliable solution

Ask gaming related questions
masky007
Posts: 4
Joined: 16 Apr 2016, 18:41

Keys get stuck - i need reliable solution

16 Apr 2016, 18:52

Maybe this has been answered somehwere else, i even found out some very similar topics on google and i tried to use them to help with my script but due my very limited coding knowledge i am not able to solve my problem, i ask your help here. Thanks.

I have written very simple script:

Code: Select all

#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.

#IfWinActive StarCraft II
	LCtrl::LShift
	LShift::LCtrl
Return
The above code made my script get stuck keys, after searching the internet i found a solution that recommended to remove the line

Code: Select all

 SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
I did that and i thought everything was fine, until last time i noticed when i opened starcraft2 (and i had the on-screen keyboard on in windows to see whats going on) i noticed when i pressed either LShift both LCtrl and Lshift were being pressed down.
After restarting the script the problem went away, why is this happening? Any proven solution?

Note: Since i have if winActive command i added my script in the startup folder (i am not sure if its relevant)

thanks
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: Keys get stuck - i need reliable solution

16 Apr 2016, 19:26

i think the keys are trigger themself. and they jump to each other so fast that you only notice a stuck.

Try LCtrl UP::LShift or LShift DOWN::LCtrl
masky007
Posts: 4
Joined: 16 Apr 2016, 18:41

Re: Keys get stuck - i need reliable solution

16 Apr 2016, 19:31

HinkerLoden wrote:i think the keys are trigger themself. and they jump to each other so fast that you only notice a stuck.

Try LCtrl UP::LShift or LShift DOWN::LCtrl
With or without the SendMode Input line?

edit: i just tried the code it gives me error
User avatar
HinkerLoden
Posts: 93
Joined: 23 Mar 2016, 07:50
GitHub: HinkerLoden

Re: Keys get stuck - i need reliable solution

17 Apr 2016, 02:18

#IfWinActive StarCraft II
LCtrl UP::LShift
LShift UP::LCtrl
Return
masky007
Posts: 4
Joined: 16 Apr 2016, 18:41

Re: Keys get stuck - i need reliable solution

17 Apr 2016, 02:58

HinkerLoden wrote:#IfWinActive StarCraft II
LCtrl UP::LShift
LShift UP::LCtrl
Return
again, when i try to run the script
Error: Invalid hotkey.

Specifically : *LCtrl Up::
Line#
003: SendMode,Input
004: SetWorkingDir, %A_ScriptDir%
007: Return
007: SetKeyDelay,-1
007:Send,{Blind}{LShift Down Temp}
---> 007: Return

The program will exit
User avatar
Nextron
Posts: 1337
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: Keys get stuck - i need reliable solution

17 Apr 2016, 04:29

AHK can detect hotkeys in two ways; as registered hotkeys or as hooked hotkeys. If they are registered they can trigger each other, which you do not want. In this case, the #if directive makes them hooked, so that's not a problem anymore.

Many processes can place a hook and the one that placed the hook last, will get input first. This will be done for elevated/admin processes first and regular processes later. From your explanation, I assume you have UAC disabled?
So starting OSK after the AHK, will have OSK see the keys first (real and artificial). Restarting the script will have AHK intercept the keys first so OSK will only see the artificial key. Regardless of the order, SC2 will see the keys after AHK and not see both keys, unless it's ran as admin and AHK is not.
masky007
Posts: 4
Joined: 16 Apr 2016, 18:41

Re: Keys get stuck - i need reliable solution

17 Apr 2016, 09:29

Nextron wrote:AHK can detect hotkeys in two ways; as registered hotkeys or as hooked hotkeys. If they are registered they can trigger each other, which you do not want. In this case, the #if directive makes them hooked, so that's not a problem anymore.

Many processes can place a hook and the one that placed the hook last, will get input first. This will be done for elevated/admin processes first and regular processes later. From your explanation, I assume you have UAC disabled?
So starting OSK after the AHK, will have OSK see the keys first (real and artificial). Restarting the script will have AHK intercept the keys first so OSK will only see the artificial key. Regardless of the order, SC2 will see the keys after AHK and not see both keys, unless it's ran as admin and AHK is not.
-yes i have UAC disabled
- i read your comment couple of times and i am not sure if i understand it completely :oops:
- what you are saying is (as my first example where i removed the

Code: Select all

SendMode Input
) i should use that and make SC2 (only) to be run with admin privileges, so SC2 will see the keys properly from AHK?
- Btw idk if it makes any difference but i have my script compiled and put in the StartUp folder (so i don't have to run the script every time i fire sc2 on)

Return to “Gaming”

Who is online

Users browsing this forum: Bing [Bot] and 44 guests