Sending Special Character for non-English languages Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Sending Special Character for non-English languages

20 Dec 2017, 12:25

Hello Everyone :D ,

I am trying to send strings in a field using AHK script. The string has some characters that is not used in English (I am portuguese speaker), like:

Code: Select all

x := "Nível A - Inspeção B"
When I send x, using send command, the x content appears weird. For instance, the character í is replaced by Ã.

I tried to use

Code: Select all

SendInput, {raw}%x%
and

Code: Select all

Send, {raw}%x%
Gave me the same result. I thought that if I could change the text format to UTF-8 mode, it could have resolved. But I don't know how.

Any clues?

Thanks!
Editor: Notepad++
"Those who wait and persist, always achieve."
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Sending Special Character for non-English languages

20 Dec 2017, 12:42

if you read it from a file:
FileEncoding , UTF-8
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Sending Special Character for non-English languages

20 Dec 2017, 12:45

although this work for me (Norwegian keyboard):

Code: Select all

x := "Nível A - Inspeção B"


f1::
SendInput, {raw}%x%
return


esc::
ExitApp
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Sending Special Character for non-English languages

20 Dec 2017, 13:02

Thanks Rindis,

FileEncodings is a good idea reading from a file. I didn't know that. Thanks
Although, I still have problem when I declare the variable content directly in the script. How do you get the same string? Maybe is keyboard layout?
Editor: Notepad++
"Those who wait and persist, always achieve."
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Sending Special Character for non-English languages

20 Dec 2017, 13:17

does your keyboard settings change with different programs? i.e. does the little language symbol (down on the left) change with different programs?
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Sending Special Character for non-English languages

20 Dec 2017, 13:44

Hi Rindis,

Yes, I do have a switch button for keyboard layout. I switch sometimes to english layout when I need. Is this the issue?
Dude, how you get the string, lol...

In your script, when I do "F1" it sends:

Nível A - Inspeção B

Thanks
Editor: Notepad++
"Those who wait and persist, always achieve."
User avatar
divanebaba
Posts: 809
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Sending Special Character for non-English languages

20 Dec 2017, 14:53

Hi.
If you want to use UTF-8-files permanently, look inside the options and choose UTF-8
Image
If you want use UTF-8 sometimes, use under Menu encoding or however in english called, convert to UTF-8.
Image

If you use Fileappend use it like below:

Code: Select all

Fileappend, %MyText%, myTextfile.txt, UTF-8
Einfach nur ein toller Typ. :mrgreen:
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Sending Special Character for non-English languages

20 Dec 2017, 15:05

I'm not sure why it works for me, there is something in manual about ansi vs unicode
https://autohotkey.com/docs/Compat.htm#Format

maybe you could try to run this?

Code: Select all

MsgBox % A_IsUnicode ? "Unicode" : "ANSI"

User avatar
divanebaba
Posts: 809
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Sending Special Character for non-English languages

20 Dec 2017, 15:09

It tells me inside the message box, that it is Unicode.
I forgot to tell, that you have to install unicode-version of Autohotkey.

EDIT: I thougt I'm answering to a question of ahkDustVorteX.
Einfach nur ein toller Typ. :mrgreen:
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Sending Special Character for non-English languages

21 Dec 2017, 07:32

Hi Rindis and divanebaba,

the code

Code: Select all

 MsgBox % A_IsUnicode ? "Unicode" : "ANSI"


tells me it is Unicode.

The weird stuff, is that my script is in UTF-8 mode. And when I import the text from a file, it sends the text perfectly. But when I send a text that is a variable defined in the script, it messes up...

Thanks
Editor: Notepad++
"Those who wait and persist, always achieve."
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Sending Special Character for non-English languages

21 Dec 2017, 08:03

Does the text display correctly in the msgbox?

Code: Select all

x := "Nível A - Inspeção B"


f1::
Msgbox  x = %x%
;~ SendInput, {raw}%x%
return


esc::
ExitApp

User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Sending Special Character for non-English languages

21 Dec 2017, 09:40

Hi Rindis,

It shows: x = Nível A - Inspeção B

Which is different from the original string x := "Nível A - Inspeção B"
Editor: Notepad++
"Those who wait and persist, always achieve."
User avatar
divanebaba
Posts: 809
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Sending Special Character for non-English languages

21 Dec 2017, 09:58

I had similar problem by changing basic-ansi-version AutoHotkey104805 to the actual Unicode-version.
It disappeared after strongly using UTF-8 versions for all files used by ahk-scripts.
Maybe you have to look more intensive what format you're using.

For me, it was huge effort to change all used files. (Postal codes and names of all cities in Germany, for example.)
I don't know another solution.
Einfach nur ein toller Typ. :mrgreen:
Rindis
Posts: 213
Joined: 23 Dec 2013, 13:58
Location: Norway
Contact:

Re: Sending Special Character for non-English languages

21 Dec 2017, 14:30

Well I'm all out of ideas, sorry.
lexikos
Posts: 9599
Joined: 30 Sep 2013, 04:07
Contact:

Re: Sending Special Character for non-English languages  Topic is solved

23 Dec 2017, 04:57

https://autohotkey.com/docs/Scripts.htm#cp

You need to tell AutoHotkey that the file is UTF-8. You can do this by saving it as UTF-8 with BOM. (Microsoft) Notepad just calls it "UTF-8".

The option divanebaba showed highlighted in Notepad++ is UTF-8 without BOM.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sending Special Character for non-English languages

23 Dec 2017, 05:46

UTF-8 ohne BOM translates to UTF-8 without BOM, one could guess that UTF-8 then would be UTF-8 with BOM. The english version of npp says UTF-8 with BOM, rather than without.

Happy hollidays :xmas:
lexikos
Posts: 9599
Joined: 30 Sep 2013, 04:07
Contact:

Re: Sending Special Character for non-English languages

23 Dec 2017, 05:58

I stand corrected...?

I assumed it would be similar to the English version, but apparently it is not.

I checked my English Notepad++ 7.3.3 installation and then updated it to 7.5.3. They both show "UTF-8" and "UTF-8-BOM", not "with" or "without". However, there is a file localization\english.xml which contains "Encode in UTF-8" and "Encode in UTF-8 without BOM", which are apparently not being used on my system. Under Preferences, New Document, I see "UTF-8" and "UTF-8 with BOM". Consistent, it is not.

I reselected "English" (it was already selected and the only option) under Localization in the Preferences window, and now the menus are showing as per english.xml.

SciTE shows "UTF-8 with BOM".
Last edited by lexikos on 23 Dec 2017, 06:05, edited 1 time in total.
Reason: I reselected English
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Sending Special Character for non-English languages

23 Dec 2017, 06:16

They both show "UTF-8" and "UTF-8-BOM", not "with" or "without".
I stand corrected, this is the case for the Encoding menu. Indeed, the Preferences -> New Document dialog says UTF-8 with BOM, and UTF-8.
Consistent, it is not.
Hopefully the functionality is consistent.
I reselected "English" (it was already selected and the only option) under Localization in the Preferences window, and now the menus are showing as per english.xml.
Interesting, I see the same behaviour. Slightly odd :think: .

Cheers :xmas:.
User avatar
ahkDustVorteX
Posts: 47
Joined: 14 May 2014, 12:08

Re: Sending Special Character for non-English languages

27 Dec 2017, 14:21

Hi Lexicos and Helgef,

You were right. I saved a new file in notepad++ as UTF-8 with BOM, and things worked.

Thanks a lot.
Editor: Notepad++
"Those who wait and persist, always achieve."

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: cinematic6436, mikeyww, sofista, Twisting and 299 guests