Why do these weird symbols sporadically show up? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Kotte
Posts: 46
Joined: 03 May 2021, 08:33

Why do these weird symbols sporadically show up?

11 Mar 2022, 06:32

These weird symbols shows up now and again and I'm wondering if anyone knows what they are and also if you know what I'm doing wrong to make them show up. This is the output I got (image as the symbols doesn't show up if copied to the browser):
weird_symbols_long.PNG
weird_symbols_long.PNG (2.22 KiB) Viewed 595 times

Expected output:

Code: Select all

{----------------------------------------------------- Some text -------------------------------------------------------

}
Any idea what's happening/what's causing it? It only happens in Notepad++ and in SciTE. I'm attaching the part of my script that caused the phenomenon this time, but it has happened with other functions/hotkeys before. I have edited the original code to include KeyWait before calling the function, but I'm still curious to know what those symbols mean, even if it was a lack of KeyWait that caused the problem.

Code: Select all


#NoEnv
#Warn
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
#Persistent

Errmsg = This hotkey was disabled in SciTE4AutoHotkey by`n"Block built in hotkeys in SciTE" in the %A_Scriptname% file.
Errmsg2 = 0

keydelay_standard := 50
SetKeyDelay keydelay_standard

center_func_np(){
   Global keydelay_standard
   SetKeyDelay -1
   temp := ClipboardAll
   Sleep 100
   Send ^c
   desired_width := 120
   line_center := desired_width/2
   Sleep 100
   Clipboard_length := StrLen(Clipboard)
   L_side := line_center-Ceil(StrLen(Clipboard)/2)-2
   R_side := line_center-Floor(StrLen(Clipboard)/2)-1
   Send, {{}{- %L_side%} %Clipboard% {-  %R_side%}{Enter 2}{}}{Up}
   Clipboard := temp
   temp := ""
   SetKeyDelay keydelay_standard
   Return
}

<^>!c::center_func_np()

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Why do these weird symbols sporadically show up?

11 Mar 2022, 07:47

It worked here. I would have a look at what is on your clipboard. You could try the following.

Code: Select all

SendInput {{}{- %L_side%}
SendInput {Text} %Clipboard% `
SendInput {- %R_side%}`n`n{}}{Up}
Or:

Code: Select all

center_func_np(){
 temp := ClipboardAll
 Clipboard := ""
 Send ^c
 ClipWait, 0
 If ErrorLevel {
  MsgBox, 48, Error, An error occurred while waiting for the clipboard.
  Return
 }
 Clipboard := Clipboard
 string := Trim(Clipboard, " `t`r`n")
 desired_width := 120
 line_center := desired_width/2
 L_side := line_center - Ceil(StrLen(string)  / 2) - 2
 R_side := line_center - Floor(StrLen(string) / 2) - 1
 SendInput {{}{- %L_side%}
 SendInput {Text} %string% `
 SendInput {-  %R_side%}`n`n{}}{Up}
 Clipboard := temp
}
Kotte
Posts: 46
Joined: 03 May 2021, 08:33

Re: Why do these weird symbols sporadically show up?

11 Mar 2022, 14:16

@mikeyww Yeah, it works for me too, 95+/100 times. That's why I'm not making any progress on debugging it. It just works every time I start trying to get it to fail. Sometimes it takes a several days before it it acts up again. I'll try your suggestion to see if some special characters breaks it.
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Why do these weird symbols sporadically show up?  Topic is solved

11 Mar 2022, 15:58

I don't have an answer, but I'm throwing some things out that may spark some insight from someone else reading this.

I assume you have the encoding in NP++ set to UTF-8-BOM (that's how I got the codes to show up like yours.)
You have two symbols shown, "US" and "ETX" (the very last one).

"US" (Unit Separator" is ASCII 31, Binary 00011111, can be typed as Ctrl-Underscore (^_) or hold Alt and type 031 on the numeric keypad.
"ETX" (End of TeXt) is ASCII 3, Binary 00000011, can be typed as Alt-003 (on numeric keypad) and is the actual character code for Ctrl-c (^c).

Something is stuffing these characters into your clipboard. Just spitballing here:

It may have something to do with the hotkey you chose (<^>!c), which, if you lifted the Alt key first, would effectively become ^c (ETX?). Perhaps use a different hotkey, like an unused function key (F12)?

Perhaps instead of sleep, you could use ClipWait, 1 after your ^c to give the clipboard time to populate with valid data.

Perhaps using SendMode Input at the top of your script instead of fiddling with KeyDelay.

I honestly don't know if any of these are the issue, but are some things to think about.

BTW, your:

Code: Select all

   Clipboard_length := StrLen(Clipboard)
   L_side := line_center-Ceil(StrLen(Clipboard)/2)-2
   R_side := line_center-Floor(StrLen(Clipboard)/2)-1
could be:

Code: Select all

   Clipboard_length := StrLen(Clipboard)
   L_side := line_center-Ceil(Clipboard_length/2)-2
   R_side := line_center-Floor(Clipboard_length/2)-1
since you already called StrLen() once to put the length into a variable, there is no need to call it again for each calculation.

Russ
Kotte
Posts: 46
Joined: 03 May 2021, 08:33

Re: Why do these weird symbols sporadically show up?

13 Mar 2022, 00:16

@RussF Well, I suspect you do have an answer :) At least to the question about the characters. And the rest don't seem that far fetched. I use UTF-8, without the BOM.

I use <^>! since AutoHotkey is missing a symbol for the AltGr key, but I think you are right. I added KeyWait when I posted my question and I haven't had the problem since.

I have other stuff that requires different KeyDelays, so I can't use SendMode Input. If I understand the documentation, it is ok to specify SendInput when I do use it.
since you already called StrLen() once to put the length into a variable, there is no need to call it again for each calculation.
What's wrong with that? Don't you have a bunch of unused variables in your code? ;) Thanks for the catch!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Marium0505, mcl and 361 guests