Jump to content

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

sometimes modifyer keys always down


  • Please log in to reply
10 replies to this topic
ArMen56k
  • Members
  • 10 posts
  • Last active: Jul 15 2015 11:43 PM
  • Joined: 29 Apr 2013

heya!

From time to time, my scripts fail, and some keys are stuck "down". Sometimes, it's Alt, or the windows key.

Even if I reload my scripts, they remain like that, and most of the time, I have to reboot the get the problem solved.

Does it happen to you? How do you manage that? Is there a way to fix this, or a little script to reset all modifyer keys?

++

 



Eedis
  • Members
  • 1775 posts
  • Last active: Aug 14 2015 06:33 PM
  • Joined: 12 Jun 2009
Send, {LWin up} ;Just change the hotkey in the braces to whatever hotkey is getting stuck.
This command, instead of sending a press of the key, it'll send the opposite and will send the release of the key.
AutoHotkey state, the forum, Poly, and Drainx1. The short story.
I love my wife, my life, my atomic-match; for giving me the greatest gift a man could ask for, such a perfect and beautiful little girl.
9rjbjc.png

Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012

I don't know what causes these problems, but there is a workaround I use.

+#s::           ;Win+Shift+s
KeyWait, Shift
KeyWait, LWin
KeyWait, RWin
;your code goes here
return

Since I applied this to all hotkeys in my master script, I have not faced this problem anymore.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


ArMen56k
  • Members
  • 10 posts
  • Last active: Jul 15 2015 11:43 PM
  • Joined: 29 Apr 2013

thx tongue.png



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

I've had this happen numerous times and the best solution is to ensure the modifier keys are up as previously pointed out. This also occurs if you attempt to block keyboard input while a modifer is down.
Although I have never had the problem persist AFTER closing or reloading the script.

 

The only problem with using a sequence of "keywaits" like this is the program simply waits for each one to be released in seuquence.

KeyWait, Shift
KeyWait, LWin
KeyWait, RWin

If the user releases the shift key but still has the Lwin down, then holds the shift key down again before releasing the Left win key  you can still end up having the shift key stuck down.

 

To have maximum reliability you really need to loop through all of the modifier and only proceed with the actions once none of them are down.

 

Here's a function  from a script of mine  which achieves this - it has more complexity than what you require (as its used by numerous other functions in my script), but im too lazy to simplify it for this post. Note: you probably don't need the 'sleep' times but the game i use it in requires these.

 

It checks the modifiers keys and if one is down it will continually re-check them every 5ms  - when they are all released it will then wait 35ms and recheck them again (this second re-check is only required for this game) - if none are down it will return otherwise it keeps going (unless a 'timeout' period was specified).

 

Also as pointed out some people have had success sending modifer up keystrokes like  {LWin up} - but I think this is hit and miss for many. Some find using Senevent or Send blind is required to 'unstick' the key.

 


ReleaseModifiers(Beep = 1, CheckIfUserPerformingAction = 0, AdditionalKeys = "", timeout := "") ;timout in ms
{
	GLOBAL HotkeysZergBurrow
	startTime := A_Tickcount

	startReleaseModifiers:
	count := 0
	firstRun++
	while getkeystate("Ctrl", "P") || getkeystate("Alt", "P") 
	|| getkeystate("Shift", "P") || getkeystate("LWin", "P") || getkeystate("RWin", "P")
	||  AdditionalKeys && (ExtraKeysDown := isaKeyPhysicallyDown(AdditionalKeys))  ; ExtraKeysDown should actually return the actual key
	|| (isPerformingAction := CheckIfUserPerformingAction && isUserPerformingAction()) ; have this function last as it can take the longest if lots of units selected
	{
		count++
		if (timeout && A_Tickcount - startTime >= timeout)
			return 1 ; was taking too long
		if (count = 1 && Beep) && !isPerformingAction && !ExtraKeysDown && firstRun = 1	;wont beep if casting or burrow AKA 'extra key' is down
			SoundPlay, %A_Temp%\ModifierDown.wav	
		if ExtraKeysDown
			LastExtraKeyHeldDown := ExtraKeysDown ; as ExtraKeysDown will get blanked in the loop preventing detection in the below if
		else LastExtraKeyHeldDown := ""
		sleep, 5
	}
	if count
	{
		if (LastExtraKeyHeldDown = HotkeysZergBurrow)
			sleep 50 ;as burrow can 'buffer' within sc2
		else sleep, 35	;give time for sc2 to update keystate - it can be a slower than AHK (or it buffers)! 
		Goto, startReleaseModifiers
	}
	return
}

isaKeyPhysicallyDown(Keys)
{
  if isobject(Keys)
  {
    for Index, Key in Keys
      if getkeystate(Key, "P")
        return key
  }
  else if getkeystate(Keys, "P")
  	return Keys ;keys!
  return 0
}



Rijul Ahuja
  • Members
  • 763 posts
  • Last active: Nov 25 2013 10:16 AM
  • Joined: 14 Mar 2012
The only problem with using a sequence of "keywaits" like this is the program simply waits for each one to be released in seuquence.
KeyWait, Shift
KeyWait, LWin
KeyWait, RWin

If the user releases the shift key but still has the Lwin down, then holds the shift key down again before releasing the Left win key  you can still end up having the shift key stuck down.

 

Good point.

Here is my code for modifiers.

While GetKeyState("Ctrl","P") || GetKeyState("LWin","P") || GetKeyState("RWin","P") || GetKeyState("Shift","P") || GetKeyState("Alt","P")
   Sleep 50

I have also noticed that physically pressing the key resolves the problem.


Abandon the forum. The community has decided in a democratic vote to leave this website because of inactive and perverse administration.

Very few of the contributing members remain here.


RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

 

Good point.

Here is my code for modifiers.

While GetKeyState("Ctrl","P") || GetKeyState("LWin","P") || GetKeyState("RWin","P") || GetKeyState("Shift","P") || GetKeyState("Alt","P")
   Sleep 50

 

Nice.

 

 

While waiting for my eggs to boil i tidied up the other function:

ReleaseModifiers(timeout := "") ; timeout in ms
{
	static	aModifiers := ["Ctrl", "Alt", "Shift", "LWin", "RWin"]
	
	startTime := A_Tickcount
	while (isaKeyPhysicallyDown(aModifiers))
	{
		if (timeout && A_Tickcount - startTime >= timeout)
			return 1 ; was taking too long
		sleep, 5
	}
	return
}

isaKeyPhysicallyDown(Keys)
{
  if isobject(Keys)
  {
    for Index, Key in Keys
      if getkeystate(Key, "P")
        return key
  }
  else if getkeystate(Keys, "P")
  	return Keys ;keys!
  return 0
}



Eedis
  • Members
  • 1775 posts
  • Last active: Aug 14 2015 06:33 PM
  • Joined: 12 Jun 2009
Hmmm.... I don't see the need for all the complex functions when you could simply send a release key press right after the push of the key.

Instead of:
Send, +a
Do:
Send, {LShift down}a{LShift up}
This will ensure, for a fact, that the key was released.
AutoHotkey state, the forum, Poly, and Drainx1. The short story.
I love my wife, my life, my atomic-match; for giving me the greatest gift a man could ask for, such a perfect and beautiful little girl.
9rjbjc.png

RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

Because that's not causing the problem. The problem is that the OTHER modifiers are being held down during the send event. AHK automatically sends the appropriate up stokes for these, but sometimes things get confused and whatever modifiers the user was holding down become stuck (down).

 

Sending {modifier up} for every key is unreliable too, as been reported in other threads. When sending these 'up' strokes, some people have required the use of SendEvent, while others have found send {blind} to be of use.



Eedis
  • Members
  • 1775 posts
  • Last active: Aug 14 2015 06:33 PM
  • Joined: 12 Jun 2009
I see, I was thinking that you were implying that the modifiers on the current hotkey were stuck down and not being released after the hotkey was used.
AutoHotkey state, the forum, Poly, and Drainx1. The short story.
I love my wife, my life, my atomic-match; for giving me the greatest gift a man could ask for, such a perfect and beautiful little girl.
9rjbjc.png

ArMen56k
  • Members
  • 10 posts
  • Last active: Jul 15 2015 11:43 PM
  • Joined: 29 Apr 2013
It works very well now. Thx for your answers!