CHR codes from 128 to 159 decimal not working

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 03 Sep 2014, 16:07

Version 1.1.14.03 on W7

Seems that AHK does not handle CHR codes from 128 to 159 decimal. I started out wanting to put the trademark symbol (153) in a message box (and a text file) and it showed up as a blank. But the copyright symbol (169) and registered trademark symbol (174) both worked fine. So I tested others and determined that the characters from 128 through 159 display (and append to files) as a blank. Any thoughts on how to fix this? Thanks, Joe

kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: CHR codes from 128 to 159 decimal not working

Post by kon » 03 Sep 2014, 16:44

Using Unicode the trademark character is 0x2122. -> Chr(0x2122)

Try running this script with Unicode and ANSI versions of AHK to see the difference:

Code: Select all

Out := "0`t"
Loop, 256
	Out .= Chr(A_Index - 1) (Mod(A_Index, 10) ? " " : "`r`n" A_Index "`t")

FileAppend, % "This script is running with " (A_IsUnicode ? "a Unicode" : "an ANSI") " version of AHK.`r`n`r`n" Out
, % FileName := A_ScriptDir "\Chr_" (A_IsUnicode ? "Unicode" : "ANSI") "_" A_Now ".txt"
Run, % FileName

guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: CHR codes from 128 to 159 decimal not working

Post by guest3456 » 03 Sep 2014, 16:55

probably has something to do with the difference between the normal ANSI charset and Windows 1252 codepage:

http://en.wikipedia.org/wiki/ISO/IEC_8859-1
http://en.wikipedia.org/wiki/Windows-1252

See the green boxes in the Windows 1252 codepage. They don't exist in other encodings.
The Windows-1252 codepage coincides with ISO-8859-1 for all codes except the range 128 to 159 (hex 80 to 9F), where the little-used C1 controls are replaced with additional characters including all the missing characters provided by ISO-8859-15. Code page 28591 aka Windows-28591 is the actual ISO-8859-1 codepage.[1]


User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 03 Sep 2014, 17:02

Thanks for the reply, Kon. I ran it on my Unicode install and it does not show 128-159. I don't have an ANSI install to test it on (and I'd rather not do an uninstall/reinstall...twice), but I see your point. Regards, Joe

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 03 Sep 2014, 17:03

guest3456,
Thanks for the reply - much appreciated. Regards, Joe

kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: CHR codes from 128 to 159 decimal not working

Post by kon » 03 Sep 2014, 17:23

JoeWinograd wrote:I ran it on my Unicode install and it does not show 128-159. I don't have an ANSI install to test it on (and I'd rather not do an uninstall/reinstall...twice)
Just an FYI, if you used the installer to install AHK you probably have the ANSI .exe file in the AHK Program Files folder already. No uninstall/reinstall required. The installer just picks the default version of AHK to use, but both should be present.

Try right clicking a script > Open With > AutoHotkey ANSI 32-Bit

Or you could download just the ANSI .exe file from the downloads page, then drag and drop the script onto the .exe.

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 03 Sep 2014, 17:58

kon,
Thanks for that explanation - I do have the ANSI 32-bit EXE in ProgFiles, and running your script with it does, indeed, show the 128-159 symbols that I was expecting. Well done! Thanks very much, Joe

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: CHR codes from 128 to 159 decimal not working

Post by lexikos » 03 Sep 2014, 20:52

This chart shows what the Unicode character codes 0x80 to 0xFF mean.

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 03 Sep 2014, 21:11

Thanks, lexikos, very helpful. Now if I can just figure out the Boolean search...

kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: CHR codes from 128 to 159 decimal not working

Post by kon » 03 Sep 2014, 21:43

I should have mentioned this before. To make your script show the trademark symbol regardless of whether you are using AHK Unicode or ANSI you could do something like this:
MsgBox, % Chr(A_IsUnicode ? 0x2122 : 0x99)

just me
Posts: 9450
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: CHR codes from 128 to 159 decimal not working

Post by just me » 04 Sep 2014, 02:01

... or use ChrA():

Code: Select all

#NoEnv
I := 31
C := ""
While (++I < 256)
   C .= (Mod(A_Index, 16) = 1 ? "`n" : "`t") . ChrA(I)
Gui, Add, Edit, w0 h0
Gui, Add, Edit, xp yp w400 r14 t8, % SubStr(C, 2)
Gui, Show, , Chr(32) - Chr(255)
Return
GuiClose:
GuiEscape:
ExitApp

ChrA(I) {
   Static ANSI := 0
   If !(A_IsUnicode)
      Return Chr(I)
   NumPut(I & 0xFF, ANSI, "UChar")
   Return StrGet(&ANSI, 1, "CP0")
}

guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: CHR codes from 128 to 159 decimal not working

Post by guest3456 » 04 Sep 2014, 02:12

the more you know..


User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 04 Sep 2014, 02:19

Thanks, kon, worked a charm! Any thoughts on my Boolean search issue?

User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: CHR codes from 128 to 159 decimal not working

Post by JoeWinograd » 04 Sep 2014, 02:27

Hi just me,
Great stuff! Thanks, Joe

Post Reply

Return to “Ask for Help (v1)”