Ctrl seems to stay pressed

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aaffe
Posts: 192
Joined: 16 Jan 2014, 04:23

Ctrl seems to stay pressed

28 Apr 2017, 02:30

I have a hotkey with Ctrl and space.
Sometimes after the hotkey the ctrl seems to stay pressed. If have added
Send,{Ctrl UP}
at the end of the hotkey, but it seems to stay pressed sometimes although. Is this a known bug or is there a solution for this problem?
Thanks!
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Ctrl seems to stay pressed

28 Apr 2017, 05:38

I've had this problem many times myself. I'd also love a solution. I play games and use many hotkeys, and often, one key seems to get stuck, usually ctrl, shift, or alt.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Ctrl seems to stay pressed

28 Apr 2017, 06:52

Show your code.
Very hard to tell without seeing some code.

I suspect that you are doing something like ^Space::a but not appreciating that what this actually does when you hit Ctrl+Space is RELEASE ctrl, send A, then hold Ctrl again (Because you asked AHK to send a, not CTRL+a).
If using syntax like this with a game, then if your KeyDelay setting is not high enough, then the game will interpret this sequence of key events wrongly, because keys go down and up within one frame of the game, and so are ignored.

In this instance, you should use ^Space::Send {Blind}a instead. Also try adding SetKeyDelay, 0, 50 to the start of the script.

When you perceive CTRL as being "Stuck" down - check the AHK key history to see what the OS thinks the state of the key is.
aaffe
Posts: 192
Joined: 16 Jan 2014, 04:23

Re: Ctrl seems to stay pressed

28 Apr 2017, 07:59

evilC wrote:Show your code.
Very hard to tell without seeing some code.

I suspect that you are doing something like ^Space::a but not appreciating that what this actually does when you hit Ctrl+Space is RELEASE ctrl, send A, then hold Ctrl again (Because you asked AHK to send a, not CTRL+a).
If using syntax like this with a game, then if your KeyDelay setting is not high enough, then the game will interpret this sequence of key events wrongly, because keys go down and up within one frame of the game, and so are ignored.

In this instance, you should use ^Space::Send {Blind}a instead. Also try adding SetKeyDelay, 0, 50 to the start of the script.

When you perceive CTRL as being "Stuck" down - check the AHK key history to see what the OS thinks the state of the key is.
Here my code. #HotkeyModifierTimeout 100 didnt work....

Code: Select all

SetTitleMatchMode, Slow
SetTitleMatchMode, RegEx
#SingleInstance force
setcapslockstate, alwaysoff
Autotrim,On
Sendmode Input
DetectHiddenWindows, On
DetectHiddenText, On
WinActivate,Force
StringCaseSense,Off
SetBatchLines -1
SetControldelay -1
SetKeyDelay -1
SetWinDelay,-1
SetMouseDelay,-1

Menu,TRAY,Color,FF00FF
Menu,TRAY,NoStandard
Menu,Tray,Add,Hilfe,Hilfe
Menu,Tray,Add,Protokoll Öffnen,FVProt
Menu,Tray,Add
Menu,Tray,Add,Programm neu starten,neustart
Menu,Tray,Add,Programm Pause AN/AUS,progpause
Menu,Tray,Add,Programm Beenden,CloseAdminLogon

Logname:=RegExReplace(A_Scriptname,"(.*)(exe|ahk)","$1txt")
IfNotExist,C:\tmp
	FileCreateDir,c:\tmp
IfExist,%logname%
	FileMove,%Logname%,c:\tmp\%logname%,1


	
Logname:="c:\tmp\" . Logname

if not A_IsAdmin
  RunAsAdmin()

Hilfedatei:="C:\tmp\" . A_Scriptname . "_Hilfe.txt"
IfExist,%Hilfedatei%
	FileDelete,%Hilfedatei%
FileAppend,
(Ltrim
Strg+Leertaste:				IP (oder IDF) in den Fastviewer kopieren und suchen (es kann ruhig mehr als die IP-Adresse markiert sein)
Strg+l oder Strg+Shift+l:	Bei Remote-Anmeldung als Administrator anmelden
Strg+Shift+s:				Bei Remote-Anmeldung als Service anmelden

Hinweis bei Windows10:
Falls die Automatische Remote-Anmeldung nicht klappt: Bitte einmal manuell als Administrator bei einer Apotheke anmelden und hierbei den Haken "Anmeldedaten speichern" setzen. Ab dann sollte es funktionieren.
),%Hilfedatei%

Loop
{
	IfWinExist,Fernwartung
	If (WinExist("Windows-Sicherheit ahk_exe FastMaster.*","(Anmeldedaten speichern)") or WinExist("Windows-Sicherheit ahk_class Credential Dialog Xaml Host ahk_exe FastMaster.*"))
	{
		If (!NotShow)
		{
			WinActivate
			Msgbox,4132,Als Administrator anmelden?,Soll ich dich automatisch als Administrator anmelden?`n`n(In 5 Sekunden wird automatisch angemeldet),5
			IfMsgbox,No
				WinWaitClose,Windows-Sicherheit ahk_exe FastMaster.*
			else
				Gosub,AdminAnmeldung
		}
	}
	Sleep 500
	Send,{Ctrl Up}
}




^l::
^+l::
^+s::
AdminAnmeldung:
	zusatz:=""
	If A_Thislabel=AdminAnmeldung
		zusatz:=" ahk_exe FastMaster.*"
	FileAppend,-> Automatische Remote-Anmeldung wurde gestartet.`n,%Logname%
	user:="xxx"
	pw:="xxx"
	If (A_ThisLabel="^+s")
	{
		user:="yyy"
		pw:="yyy"
	}
	
	;Neu ab Windows10
	If WinExist("Windows-Sicherheit ahk_class Credential Dialog Xaml Host ahk_exe FastMaster.*")
	{
		NotShow:=1
		Blockinput,Mouse
		Coordmode,Mouse,Relative
		WinActivate
		Click,103,291
		Send,{TAB}
		WinActivate
		Send,{Space}
		Sleep 100
		WinActivate
		Send,{TAB 2}
		WinActivate
		Send,{Space}
		WinActivate
		Sleep 100
		Click,96,255
		Send,%user%{TAB}%pw%{ENTER}
		Coordmode,Mouse,Screen
		Blockinput,Off
		;Hier neu
		Sleep 1000
		WinWait, Windows-Sicherheit ahk_class Credential Dialog Xaml Host ahk_exe FastMaster.*,,5
		If WinExist("Windows-Sicherheit ahk_class Credential Dialog Xaml Host ahk_exe FastMaster.*")
		{
			Blockinput,Mouse
			Coordmode,Mouse,Relative
			WinActivate
			Send,{TAB 2}
			WinActivate
			Send,{Space}
			Sleep 100
			WinActivate
			Send,{TAB 2}
			WinActivate
			Send,{Space}
			WinActivate
			Sleep 100
			Send,%user%{TAB}%pw%{ENTER}
			Coordmode,Mouse,Screen
			Blockinput,Off
		}
		NotShow:=0
		
	}
	Else	
	IfWinExist,Windows-Sicherheit%zusatz%,(Anmeldedaten speichern)
	{
		IfWinNotActive,Windows-Sicherheit%zusatz%,(Anmeldedaten speichern), WinActivate, Windows-Sicherheit%zusatz%,(Anmeldedaten speichern)
		WinWaitActive,Windows-Sicherheit%zusatz%,(Anmeldedaten speichern)
		sleep, 300
		Send, {Down}%user%{TAB}%pw%{ENTER}	
		Sleep 1000
		ControlSetText,Edit1,%user%,Windows-Sicherheit%zusatz%,(Anmeldedaten speichern)
		ControlSetText,Edit2,%pw%,Windows-Sicherheit%zusatz%,(Anmeldedaten speichern)
		ControlClick,Button2,Windows-Sicherheit%zusatz%,(Anmeldedaten speichern)
	}
	Else 
	IfWinExist,Fernwartung 
	{
		IfWinNotActive, Fernwartung, , WinActivate, Fernwartung, 
		WinWaitActive, Fernwartung,
		MouseClick, left,  966,  474
		Sleep, 100
		Send,%user%{TAB}%pw%{ENTER}
	}
	Send,{Ctrl up}
Return

Ctrl & Space::
	IP=
	altClip:=ClipBoard
	Send,^c
	clipwait,3
	Sleep 300
	StringReplace,IP,clipboard,`n,,ALL
	StringReplace,IP,IP,`r,,ALL
	StringReplace,IP,IP,%A_SPACE%,,ALL
	FoundPos:=RegExMatch(IP,"10\.(\d*)\.(\d*)\.(\d*)")	
	If (FoundPos > 0)
	{
  	IP:=RegExReplace(IP,".*10\.(\d*\.\d*)\.\d*.*","10.$1.")
  	;Tooltip,IP %IP% gefunden!,15,15
	}
	else
	{
			FoundPos:=RegExMatch(IP,"(\d*)")
			If (FoundPos > 0)
				IP:=RegExReplace(IP,"[^0-9]","")
	}
	clipboard:=IP
	FileAppend,%A_YYYY%-%A_MM%-%A_DD% %A_Hour%:%A_Min%:%A_Sec% - %IP% wurde gesucht.`n,%Logname%
	IfWinExist,Fernwartung
	{
		 WinActivate
		 WinMaximize,Fernwartung
		 WinWaitActive,Fernwartung,,3
		 If !ErrorLevel
		 {
		   Coordmode,Mouse,Relative
		   ControlGetPos,X,Y,,,FWinCustomControl1,Fernwartung
		   If X
		   {
			 x:=x+5
			 y:=y+5
			 MouseClick,Left,%X%,%Y%
			 Sleep 100
			 MouseClick,Left,16,69
		   }
		   ControlGetPos,X,Y,,,SysTreeView322,Fernwartung
			;MouseClick,Left,%X%,%Y%
		   x:=x+20
		   y:=y+20
		   Sleep 200
		   Send,{UP}
			Sleep 200
		 WinGet,Controls,ControlList,Fernwartung
		 EditX:=RegExReplace(Controls,"m).*(Edit\d*).*","$1")
		 ControlGetPOs,X,Y,,,%EditX%,Fernwart
		 x:=x+10
		 y:=y+10
		 ;msgbox EditX: %EditX% x: %x% y: %y%
		 MouseClick,Left,%X%,%Y%,2
		 Sleep 100
		 Send,{Del 15}{BS 15}
		Send,^v
		 Sleep 100
		 Send,{ENTER}
		}
	}
	Else
	{	
		fastmaster=
		Loop,D:\Dokus\FastMaster*.exe
		{
			IfNotInstring,A_LoopFileName,Supported
			{
				Run, % fastmaster:=A_LoopFileFullPath
				Sleep 2000
			}
		}
	
		If fastmaster=
		 MsgBox,16,Start Fastviewer first!,I really wished your FastViewer was started!`n`nAber wenn du ihn nach D:\Dokus legst`, starte ich ihn dir das nächste Mal automatisch!,3
		FileAppend,--> Fastviewer war nicht gestartet!`n,%Logname%
    }
   ClipBoard:=altClip
  Settimer,ToolTipOff,-1
  Send,{Ctrl up}
Return
ToolTipOff:
	Sleep 1500
	Tooltip
Return
FVProt:
IfExist,%logname%
	Run,%Logname%
else
	Msgbox,64,Fehler!,%logname% existiert (noch?) nicht.
Return
CloseAdminLogon:
	ExitApp
Return

neustart:
	Reload
	Exitapp
Return

progpause:
	Pause,Toggle
Return

Hilfe:
	IfExist,%Hilfedatei%
		Run,%Hilfedatei%
	else
		Msgbox,64,Fehler,%Hilfedatei% existiert nicht!
Return


RunAsAdmin() {
global
Loop, %0%  ; For each parameter:
    params .= A_Space . %A_Index%
local ShellExecute
ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
if not A_IsAdmin
    {
      A_IsCompiled
        ? DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
        : DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
      ExitApp
    }
}
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Ctrl seems to stay pressed

28 Apr 2017, 08:13

I don't think my suggestion applies to your case.
It might not matter, but consider this,
The manual wrote: For standard modifier keys, normal hotkeys typically work as well or better than "custom" combinations. For example, <+s:: is recommended over LShift & s::.
That is, try ^Space:: instead of Ctrl & Space::.
aaffe
Posts: 192
Joined: 16 Jan 2014, 04:23

Re: Ctrl seems to stay pressed

28 Apr 2017, 08:29

Helgef wrote:I don't think my suggestion applies to your case.
It might not matter, but consider this,
The manual wrote: For standard modifier keys, normal hotkeys typically work as well or better than "custom" combinations. For example, <+s:: is recommended over LShift & s::.
That is, try ^Space:: instead of Ctrl & Space::.
I will try this, thanks!
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Ctrl seems to stay pressed

28 Apr 2017, 09:02

I've had this problem with something as simple as this:

Code: Select all

^p::
Send m
Sleep 500
Send {Up}{Return}{Esc}
Return
After using this hotkey, sometimes CTRL gets "held down" until I press it again. I haven't tried using setkeydelay, might help. Big problem with testing is that the problem occurs randomly and rarely.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Ctrl seems to stay pressed

28 Apr 2017, 09:32

Does this work? Ctrl Up, or LCtrl Up?

Code: Select all

^p::
Send {Ctrl Up}m
Sleep 500
Send {Up}{Return}{Esc}
Return
One thing I do that is similar:

Code: Select all

RAlt & Left:: ;internet explorer - tab back/forward
SendInput {RAlt Up}!{Left}
return

RAlt & Right:: ;internet explorer - tab back/forward
SendInput {RAlt Up}!{Right}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Ctrl seems to stay pressed

28 Apr 2017, 10:53

aaffe wrote:#HotkeyModifierTimeout 100 didnt work....
If anything, I'd try something lower than the default 50, perhaps 25.
@ jeeswg, does SendInput {RAlt Up}!{Left} work better for you than SendInput,!{Left} ? :angel:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Ctrl seems to stay pressed

28 Apr 2017, 12:02

@Helgef, you had me worried I was going to do a facepalm, but actually no. I tried !{Left} and !{Right}, and it worked very intermittently, often not working, and causing the menu bar to appear sometimes. The {RAlt Up} version that I shared worked really smoothly. Before that I was using a method involving KeyWait (see below). Nice emoticon usage btw hehe.

Code: Select all

;good method

RAlt & Left:: ;internet explorer - tab back/forward
SendInput {RAlt Up}!{Left}
return

RAlt & Right:: ;internet explorer - tab back/forward
SendInput {RAlt Up}!{Right}
return

;==================================================

;other method

;RAlt & Left:: ;internet explorer - tab back/forward
BlockInput, On
ToolTip, release AltGr key
KeyWait, Alt
ToolTip
SendInput !{Left}
BlockInput, Off
return

;RAlt & Right:: ;internet explorer - tab back/forward
BlockInput, On
ToolTip, release AltGr key
KeyWait, Alt
ToolTip
SendInput !{Right}
BlockInput, Off
return

;==================================================

;problem method

;RAlt & Left:: ;internet explorer - tab back/forward
SendInput !{Left}
return

;RAlt & Right:: ;internet explorer - tab back/forward
SendInput !{Right}
return

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Rangana Fernando
Posts: 1
Joined: 16 Mar 2017, 09:45

Re: Ctrl seems to stay pressed

25 Mar 2022, 10:02

never use < in hotkey
this character leads to stay pressed hotkey

i mean never use like below
<^<+z::

bless you all.
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: Ctrl seems to stay pressed

25 Mar 2022, 10:40

Why do you say that? The < symbol just means to use the left key of a pair of keys, so <^<+z:: just says to use the left Ctrl key and the left Shift key along with the Z key.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, jaka1, rc76 and 319 guests