problem: first key input ignored after mouse click

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
quipstad
Posts: 4
Joined: 24 Mar 2017, 09:24

problem: first key input ignored after mouse click

24 Mar 2017, 10:36

Hi there, I'm hoping someone can please help me troubleshoot a recent issue with a previously working (and very simple) code. This code worked great for a year and has only been giving me frustration recently (I don't know of any updates done to my system that would have affected this).

I am remapping {Enter} to +{Enter} when in a specific document of Microsoft Word, to create a line break in lieu of a paragraph break.
When I click anywhere in the document, {Enter} produces {Enter} the first time, but {Enter} again returns +{Enter} as requested.
If I click inside the document again, the problem is reproduced.
Every time I click the left mouse button, the immediately following {Enter} ignores the script and creates a new paragraph.
This happens regardless of how long I wait after clicking into the document. The first {Enter} doesn't follow the script.

The following code worked perfectly for a year, but in the past few weeks the above problem has been happening consistently.
----------------
#NoEnv
#SingleInstance force
SetTitleMatchMode 2
SendMode, Input

#IfWinActive, Document.docx
$+Enter::Send, {Enter}
$Enter::Send, +{Enter}
return
----------------

I've tried removing the dollar signs but no change. I've tried removing the explicit Send command to treat it as a simple conditional remap, but still no change.
Tried various other arrangements that functioned similarly, but all iterations also gave me the same problem.

I am on AHK version 1.0.48.05 due to my work computer making it difficult to install/update applications.

Thank you!
CrescentSurfer
Posts: 10
Joined: 21 Mar 2017, 22:56

Re: problem: first key input ignored after mouse click

25 Mar 2017, 03:51

Do you have any other scripts running? I tested your code and it seems to work flawlessly for me with Word 2010, after I change the #ifwinactive directive so it actually matches my Word window.

btw, I believe the Return is supposed to mark the end of the Autoexecute section, so it should appear before the hotkey definitions:

Code: Select all

#NoEnv
#SingleInstance force
SetTitleMatchMode 2
SendMode, Input
return

#IfWinActive, ahk_exe WINWORD.EXE
$+Enter::Send, {Enter}
$Enter::Send, +{Enter}


User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: problem: first key input ignored after mouse click

25 Mar 2017, 05:05

Post the AHK log from 'last lines executed' and also from 'key history' after you had both a successful and unsuccessful replacement.
CrescentSurfer wrote:I believe the Return is supposed to mark the end of the Autoexecute section
Although Return explicitly ends the auto-execute section, it also ends at the first hotkey; so technically redundant.
quipstad
Posts: 4
Joined: 24 Mar 2017, 09:24

Re: problem: first key input ignored after mouse click

25 Mar 2017, 09:10

Thanks for the responses! I do have 8 or so other running scripts, most of which are to open a specific directory with a keyboard shortcut. I can provide information on those scripts as well, but I've never had a problem with them all working together.

I'll post the log as soon as I'm back at work on Monday. Thanks again for the help!
quipstad
Posts: 4
Joined: 24 Mar 2017, 09:24

Re: problem: first key input ignored after mouse click

27 Mar 2017, 08:36

Okay I have the log. I began by reloading the script, then clicked into the WinWord window, hit enter and the script did not correct it; backspaced and hit enter again and the script corrected it.

This is the complete log starting at the reload and including one failed correction and one successful correction:

002: Return (5.35)
002: SetKeyDelay,-1
002: Send,{Blind}+{Enter DownTemp}
002: Return (0.13)
002: SetKeyDelay,-1
002: Send,{Blind}{Enter Up}
002: Return (2.95)
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: problem: first key input ignored after mouse click

27 Mar 2017, 11:57

Good, now the same for the key history, because so far the hotkey seems to not have triggered.
quipstad
Posts: 4
Joined: 24 Mar 2017, 09:24

Re: problem: first key input ignored after mouse click

27 Mar 2017, 12:58

Key History:

Code: Select all

The oldest are listed first.  VK=Virtual Key, SC=Scan Code, Elapsed=Seconds since the previous event.  
Types: h=Hook Hotkey, s=Suppressed (blocked), i=Ignored because it was generated by an AHK script, a=Artificial, #=Disabled via #IfWinActive/Exist.

VK  SC	Type		Up/Dn	Elapsed	Key			Window
-------------------------------------------------------------------------------------------------------------
74  03F	 		d		11.89		F5			C:\...\fix-line-breaks.ahk 
74  03F	 		u		0.08		F5             	
0D  11C	 		d		4.65		Num Enter	Current Month.docx - Microsoft Word
0D  11C	 		u		0.13		Num Enter      	
08  00E	 		d		0.58		Backspace      	
08  00E	 		u		0.14		Backspace      	
0D  01C	h		d		0.27		Enter          	
A0  02A	i		d		0.00		Shift          	
0D  01C	i		d		0.00		Enter          	
A0  02A	i		u		0.00		Shift          	
0D  01C	h		u		0.11		Enter          	
0D  01C	i		u		0.00		Enter          	
08  00E	 		d		0.38		Backspace      	
08  00E	 		u		0.11		Backspace      	
74  03F	 		d		3.71		F5			C:\...\fix-line-breaks.ahk             	
Thanks again!
Edit: Sorry for the terrible formatting. It looked nice until I published the post. Not sure how to preserve tabbing, etc.
Last edited by Nextron on 29 Mar 2017, 09:56, edited 1 time in total.
Reason: Added [code] tags.
MaxAstro
Posts: 557
Joined: 05 Oct 2016, 13:00

Re: problem: first key input ignored after mouse click

28 Mar 2017, 10:49

@CrescentSurfer You are mistaken, by the way; the autoexecute section does not need to have a return. I'm surprised putting a return there doesn't mess things up, actually. As written the code doesn't need a return at all; single-line hotkeys don't have to return.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: problem: first key input ignored after mouse click

29 Mar 2017, 10:04

From your logs only a single enter input is visible which triggers the remapping. The first enter doesn't even reach this script and is likely intercepted by another hook or less likely another active administrative program.

So please try the following; with all your scripts running, terminate this script and then start it again and see if it works. If not, terminate it and start it as administrator. If it still doesn't work, terminate all other scripts and retry.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mebelantikjaya and 291 guests