CTRL Key stuck after script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Railang
Posts: 7
Joined: 22 May 2017, 15:02

CTRL Key stuck after script

23 May 2017, 13:55

I am having problems with my script freezing up after some commands, seems to decay and only goes away after I press CTRL after running a script.
The freezing seems to be holding down the CTRL key.
Could somebody take a look and see if I messed anything up?

;Schedule Yourself for the next 30 minutes
^]::
CoordMode, Mouse, Screen
MouseClick, Left, 3693, 350
Sleep, 50
MouseClick, Left, 3224 , 447
Sleep, 25
FormatTime, currentdatetime,, hh:mm
SendInput %CurrentDateTime%
MouseClick, Left, 3777, 443
var:=A_Now ; get the time
EnvAdd, Var, 30 ,Minits ; add 30 minits
FormatTime, var,%var%, hh:mm ; format the time
SendInput,%Var% ; display the new time
MouseClick, Left, 2966, 611
Return

;Todays date
^\::
FormatTime, CurrentDateTime,, dd/MM/yy
SendInput %CurrentDateTime%
Return

;Callback
^p::
SendInput,
(
Please give us a call back at your earliest convenience{!}
)
Return

;Is there anything else
^i::
SendInput,
(
Is there anything else I can help you with?
)
Return

;Left A VM
^1::
SendInput,
(
*******************We've Left A Voice Mail*******************

WE NEED THE FOLLOWING FROM YOU:

THINGS YOU CAN TRY IN THE MEANTIME:

OUR NEXT STEPS: We will need additional information. Please respond to this email, or contact us at 801-562-8778.
If there is a window of time you would like to schedule a call, let us know and we will do our best to reschedule during that window of time.

Called Client (y/n): Y
Emailed Client (y/n): Y

******************We'll Continue To Follow-up*****************
)
Return

;Client Coms
^2::
SendInput,
(
******************NEW Message from i.t.NOW******************




Thank you,
Ian

OUR NEXT STEPS: Waiting client response

Called Client (y/n): Y
Emailed Client (y/n): Y

**********************************************************
)
Return

;Ticket Resolution
^3::
SendInput,
(
**********************Ticket Resolution**********************

TODAY WE ASSESSED:

SOLUTION:

Called Client (y/n): Y
Emailed Client (y/n): Y

*********************************************************
Upon closing your request, you may receive the world's simplest survey.
Just click on the appropriate icon to indicate your satisfaction level and let us know how we are doing{!}

If you need further assistance please reach us at 801-562-8778, help@itnow.net or on the web at http://itnow.net

We make IT look easy{!}
)
Return

;New Ticket
^4::
SendInput,
(
*************************************
Caller Name (First/Last):

Best Contact Number/Ext:

Problem Description:

Do you have an existing ticket this issue is in regards to (ie: New Workstation): No

When did your issue start: Today

Is this a new issue, or has it occurred before: New

How many devices/people are affected: 1

i.t.NOW Management ID:

Additional notes: N/A
*************************************
TICKET NUMBER PROVIDED TO USER: YES
*************************************
)
Return

;Ticket Escalation
^5::
SendInput,
(
******************Ticket Escalation**********************

Priority of request:

Date/Time REQUIRED:

Tech to escalate to:

Estimated time required:

Problem description:

Troubleshooting performed:

Suspected causes:

i.t.NOW Management ID:
Configuration added to ticket:

Computer/Server up-time:

Computer/Server Operating System:

Log in info:

Additional Notes:

******************************************************
)
Return
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: CTRL Key stuck after script

23 May 2017, 15:17

When the hotkey triggers, CTRL is held, because your hotkeys use CTRL

You use SendInput, and I am not hugely familiar with it's idiosyncrasies, but try sending a Ctrl up event as soon as the hotkey starts processing, eg:

Code: Select all

^\::
	Send Ctrl up
Other workarounds may be:

Do not use Ctrl in your hotkeys (Try remapping the Function keys, they are largely useless these days anyway)
Copy the text to the clipboard and then just paste the clipboard, rather than sending keystrokes
Railang
Posts: 7
Joined: 22 May 2017, 15:02

Re: CTRL Key stuck after script

23 May 2017, 16:45

Thanks I will give this a try and let you know if it works.
Railang
Posts: 7
Joined: 22 May 2017, 15:02

Re: CTRL Key stuck after script

25 May 2017, 12:17

I tried this for a while and unfortunately I am still having the problem. Remapping as function keys works, however using the ctrl key would be very useful if I could get it working somehow.
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: CTRL Key stuck after script

25 May 2017, 16:58

I often have issues with modifier keys getting "stuck" in my scripts - usually when I use blockinput but sometimes other times. One thing I've had some success with is making sure the hotkey doesn't do anything until I release the modifier keys. You can do this:

Code: Select all

while (GetKeyState("Ctrl"))
	sleep, -1
If you put that as the first two lines of the hotkey, it will make sure nothing else happens until you release control, which should help.
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: CTRL Key stuck after script

26 Apr 2018, 04:40

MaxAstro wrote:I often have issues with modifier keys getting "stuck" in my scripts - usually when I use blockinput but sometimes other times. One thing I've had some success with is making sure the hotkey doesn't do anything until I release the modifier keys. You can do this:

Code: Select all

while (GetKeyState("Ctrl"))
	sleep, -1
If you put that as the first two lines of the hotkey, it will make sure nothing else happens until you release control, which should help.
DO NOT DO THIS!

Observe what happens if you use that technique in some code - run the following code and hold F1, hold F2, then release F1.
The release for F1 is NOT triggered until you release F2, and also notice that A_ThisHotkey is wrong.

Code: Select all

F1::
    while (GetKeyState(A_ThisHotkey))
        Sleep -1
	Tooltip % "F1 RELEASE @ " A_TickCount "(A_ThisHotkey = " A_ThisHotkey ")", 0, 0, 1
	return

F2::
    while (GetKeyState(A_ThisHotkey))
        Sleep -1
	Tooltip % "F2 RELEASE @ " A_TickCount "(A_ThisHotkey = " A_ThisHotkey ")", 0, 30, 2
	return
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: CTRL Key stuck after script

26 Apr 2018, 10:22

Okay, yes, it doesn't work if you are triggering multiple hotkeys simultaneously because of limitations with GetKeyState. In my use case as far as I can tell it works fine because all of my hotkeys are discreet; they never trigger concurrently. I also don't use A_ThisHotKey.

That all said, in most cases, putting a one second sleep at the start of the script - long enough to be sure the key has been released - probably works just as well.

Alternatively, would doing this achieve the "wait until released" while dodging the issues with GetKeyState?

Code: Select all

Loop
{
	Sleep, 400
	if (!GetKeyState("Ctrl"))
		break
}
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: CTRL Key stuck after script

26 Apr 2018, 10:59

No, that code still suffers from the exact same issues (It's still a blocking wait). Bear in mind that Sleep is still a blocking call in AHK! Whilst, for example, a Sleep -1 yields to other processes, it DOES NOT yield to suspended AHK threads (Only the finishing of the thread that interrupted it does)

The ONLY ways to handle key release detection with no side-effects are to use an Up event hotkey, or a SetTimer that checks the state.
This thread has more information as to what is going on and why it is a problem: https://autohotkey.com/boards/viewtopic.php?t=19745
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: CTRL Key stuck after script

26 Apr 2018, 11:38

try puting this at the end

Code: Select all

Send, {Blind}
:wave: There is always more than one way to solve a problem. ;)
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: CTRL Key stuck after script

26 Apr 2018, 12:09

it did help me a lot in my scripts where ctrl being stuck

https://autohotkey.com/docs/commands/Send.htm#blind
:wave: There is always more than one way to solve a problem. ;)
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: CTRL Key stuck after script

27 Apr 2018, 10:14

Sorry if I'm not understanding correctly, but wouldn't that mean that ANY blocking wait, regardless of what it is waiting for, would have that issue?
christian_bailey
Posts: 1
Joined: 30 Aug 2019, 09:27

Re: CTRL Key stuck after script

30 Aug 2019, 09:32

I was having the same issue. This solved it for me: https://autohotkey.com/board/topic/88715-control-key-getting-stuck/

TLDR, remove this from top of script:
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 350 guests