Line cleanup script is acting weird

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Line cleanup script is acting weird

Post by newcod3r » 19 May 2022, 00:34

and I don't understand why. The click seems to highlight the previous sentence even though it's correctly positioned on the sentence I want. What could be the issue?

Code: Select all

	+Backspace::
		~= & Backspace:: ; 1 Backspace
		Click
		Sleep 350
	SetKeyDelay, 100
Send `b `
return
https://streamable.com/hqs8sl

Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Line cleanup script is acting weird

Post by Rohwedder » 19 May 2022, 01:12

Hallo,
Hotkey +Backspace::
the Click sent with Shift marks different areas depending on the position of the caret, which are then deleted with Backspave + Space. No idea what you want to do with this.
Hotkey ~= & Backspace::
Even more incomprehensible for me!

User avatar
boiler
Posts: 16911
Joined: 21 Dec 2014, 02:44

Re: Line cleanup script is acting weird

Post by boiler » 19 May 2022, 02:49

I also don’t understand what your code is trying to accomplish and how, but can I suggest a change to how your code is indented in order to make it easier to follow logic-wise? (especially in the context of code around it in a larger script) If you have some reasoning behind how you’ve indented it, I’d like to hear it because it looks almost totally random. Here is how I would indent it:

Code: Select all

+Backspace::
~= & Backspace:: ; 1 Backspace
	Click
	Sleep 350
	SetKeyDelay, 100
	Send `b `
return

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: Line cleanup script is acting weird

Post by newcod3r » 19 May 2022, 03:13

the indenting is correct in notepad++ but not sure why it's off when pasted in the forums.

It is meant to collapse multiple lines into 1 line, hence I hover over the start of a stray sentence, so that it can collapse back to the previous line. I know regex can do this but sometimes the output is not as intended, so this is a quick fix.

How do I prevent the Shift from moving my caret position then?

User avatar
boiler
Posts: 16911
Joined: 21 Dec 2014, 02:44

Re: Line cleanup script is acting weird

Post by boiler » 19 May 2022, 06:38

newcod3r wrote: the indenting is correct in notepad++ but not sure why it's off when pasted in the forums.
When I paste your code in Notepad++, it's showing it exactly as it is here in the forum posting, as expected. Perhaps you made some custom tab stops that are causing one or more tabs to not actually indent at all.

newcod3r wrote: It is meant to collapse multiple lines into 1 line, hence I hover over the start of a stray sentence, so that it can collapse back to the previous line. I know regex can do this but sometimes the output is not as intended, so this is a quick fix.
So I guess you're saying you hover the mouse and press Shift+Backspace as a shortcut instead of clicking the mouse and pressing backspace and space yourself. It doesn't really seem shorter, but OK.

newcod3r wrote: How do I prevent the Shift from moving my caret position then?
You need to have it wait for you to release the Shift key since you are holding it down when you invoke the hotkey and Notepad++ is doing what is expected when you Shift+Click on a location. It selects everything between there and where your caret was before the click.

Code: Select all

+Backspace::
~= & Backspace:: ; 1 Backspace
	KeyWait, Shift
	Click
	Sleep 350
	SetKeyDelay, 100
	Send `b `
return
Alternatively, you could have it send {Shift up} but I like waiting for the key to be physically released instead since you are going to do that anyway. There can be timing issues if you artificially release it which would involve another Sleep to avoid.

newcod3r
Posts: 505
Joined: 30 Sep 2021, 02:16

Re: Line cleanup script is acting weird

Post by newcod3r » 19 May 2022, 06:47

ah yes you're right, keywait is the missing ingredient here. Thank you again!

The identation seems to work fine now, so I guess it's a one-off issue.

Post Reply

Return to “Ask for Help (v1)”