Checking for newline

Get help with using AutoHotkey and its commands and hotkeys
pddzaic
Posts: 3
Joined: 15 Apr 2016, 03:48

Checking for newline

12 Jan 2018, 03:27

How can I check, if a character is a newline?

The following does not work:

Code: Select all

#<::
Loop {
        Send, +{Left}       ; select text by single characters to the left (Send, +^{Left} for whole word)
	Send, ^c              ; copy selected text
	ClipWait              ; wait until the clipboard contains data
	StringLeft, MySelectedChar, clipboard, 1 ; save the first character from the left side of the clipboard in the variable MySelectedChar
	if (MySelectedChar = `n) {
		MsgBox newline char detected
	}
}
The reason is: If autohotkey is started, all characters to the left should be selected until a SPACE is detected. The problem is, if my string start with the line, than no SPACE could be detected.
BoBo
Posts: 2519
Joined: 13 May 2014, 17:15

Re: Checking for newline

12 Jan 2018, 04:05

characters to the left should be selected until a SPACE is detected. The problem is, if my string start with the line, than no SPACE could be detected.
You should definitely go/request support for RegEx to solve this issue!
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Checking for newline

13 Jan 2018, 04:52

Image

You can try this but shift+left_arrow does not stop on a space when i tried it on my editor window, i had to include the space in the regexmath too:

Code: Select all

regexmatch(clipboard,"`a)(\r| )")

Code: Select all

#<::
Loop 200  ;just to be safe
{
  Send, +{Left}       ; select text by single characters to the left (Send, +^{Left} for whole word)
	Send, ^c              ; copy selected text
	ClipWait              ; wait until the clipboard contains data

if regexmatch(clipboard,"`a)(\r)")  ; breaks at "newline"  for "newline" and "space" use regexmatch(clipboard,"`a)(\r| )")
break
}
ToolTip, %clipboard%
return
esc::exitapp
soundcloud.com/user-32706894
pddzaic
Posts: 3
Joined: 15 Apr 2016, 03:48

Re: Checking for newline

08 Feb 2018, 08:16

Could you please explain a little bit the code:

Code: Select all

regexmatch(clipboard,"`a)(\r| )")
especially the "`a)("

I think "`a" means "beginning of line, but why then ")("
User avatar
divanebaba
Posts: 779
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Checking for newline

08 Feb 2018, 09:21

Hello pddzaic,
RegEx seems really nice, but learning it means coding tons of bits an bytes.
Your code has only small issues to accurately work.Look my modifications below. It should work

Code: Select all

#<::
Loop {
	clipboard =				; clear clipboard it before you use ClipWait
        Send, +{Left}		; select text by single characters to the left (Send, +^{Left} for whole word)
	Send, ^c				; copy selected text
	ClipWait				; wait until the clipboard contains data
	StringLeft, MySelectedChar, clipboard, 1 ; save the first character from the left side of the clipboard in the variable MySelectedChar
	if (MySelectedChar = "`n") {
		MsgBox newline char detected
	}
}
Maybe possible to use code below, if there is a linefeed `r inside

Code: Select all

...
StringLeft, MySelectedChar, clipboard, 2
if (MySelectedChar = "`r`n")
...

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], DMDComposer, Google [Bot] and 259 guests