problems with diacritics Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
thelegend
Posts: 13
Joined: 23 Mar 2021, 15:29

problems with diacritics

23 Mar 2021, 16:03

Hello all! I'm a new AHK user and this is my first post.

INTRODUCTION
I write mostly in French, so I have to use diacritics (accented characters), such as à, é, è, ï, ô. With my keyboard layout, the way to write "à," for example, is by pressing the acute accent key (SC028, see picture attached), then the "a".

I'm using AHK v. 1.133.06, 32-bits on Windows 10, 64-bits. Everything is up-to-date.

PROBLEM
When I add hotstrings to a .ahk files, I can't use my accent key as before. So if I do the same motion than explained above, instead of getting "à", I get "``a". I noticed that I can have a ton of shortcuts without problem. But when I add a hotstring­, it starts doing it.

MY TROUBLESHOOTING
1. I learned that the .ahk file has to be UTF-8, so I did that.

2. I closed all my running script and created another one with only the classic "::btw::by the way". When it is activated, the same problem arrives. When it is not, everything is fine.

3. I found this thread (https://www.autohotkey.com/boards/viewtopic.php?t=63557), and the problem seemed similar to mine. I took the code below and tested it.

Code: Select all

SC028::
	Input, Key, L1
	Send {SC028}%Key%
Return
At first, it made everything work, except in Microsoft Word, where it so happens I have to spend most of my time. But shortly after that, it stopped working, so my problem is again, global.

----

Please help me. I'd rather find a real and elegant solution than to start having hotstrings for "``a" and the like... if it's at all possible.
Attachments
keyboard.png
keyboard.png (59.89 KiB) Viewed 1681 times
Rohwedder
Posts: 7687
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: problems with diacritics

24 Mar 2021, 02:43

Hallo,
I write mostly in German and use à only rarely. But the method here is identical:
With my german keyboard layout, the way to write "à," for example, is by pressing the acute accent key ,then the "a".

Your PROBLEM:
When I add hotstrings to a .ahk files, I can't use my accent key as before. So if I do the same motion than explained above, instead of getting "à", I get "``a". I noticed that I can have a ton of shortcuts without problem. But when I add a hotstring­, it starts doing it.

Very strange!
Autohotkey has no effect whatsoever on the way accent characters are written here,
whether in Word 2019 or anywhere else.
Hotstrings can even write accent characters and accent characters can trigger Hotstrings:

Code: Select all

::dias::à, é, è, ï, ô
::à::lowercase a with grave
::é::ï
User avatar
thelegend
Posts: 13
Joined: 23 Mar 2021, 15:29

Re: problems with diacritics

24 Mar 2021, 10:26

Hello Rohwedder!

Thanks for replying.

So I made a script using only the code you provided. Look what it does. I used, in order, the hotstrings you suggested.
Attachments
still doing it.gif
What happens when I try to include hotstrings in my scripts
still doing it.gif (499.3 KiB) Viewed 1646 times
Rohwedder
Posts: 7687
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: problems with diacritics

24 Mar 2021, 11:13

Just an idea!
Check the encoding of your scripts. It must be UTF-8 BOM, not UTF-8
User avatar
thelegend
Posts: 13
Joined: 23 Mar 2021, 15:29

Re: problems with diacritics

25 Mar 2021, 09:44

Rohwedder wrote: Check the encoding of your scripts. It must be UTF-8 BOM, not UTF-8
I saw this tip somewhere and I did change it to UTF-8 BOM — no idea what that means or changes, though. You can look again at my GIF, at the bottom of the window where you script is.

I should've mentioned that in my initial request... sorry about that!
Rohwedder
Posts: 7687
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: problems with diacritics

25 Mar 2021, 10:34

Non-German keyboard layouts do not work properly here, not even the US layout.
I can't reproduce this weird ``a effect with my German keyboard layout.
Perhaps?: J'ai besoin d'aide
https://www.autohotkey.com/boards/viewforum.php?f=55
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: problems with diacritics

25 Mar 2021, 18:18

Hi three :wave: , You remined me of my time when I was typing my "memoire" for the university,

here is the code I was usnig

just hold the "key" to change its state

Code: Select all

#NoEnv 
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance Force
#InstallKeybdHook
#MaxHotkeysPerInterval 200
;Debug ###########
;SetTimer, varCheck, 500
;################

;Change this as you like or add more
a := [1,"à","á","â","ã","ä","æ"]
c := [1,"ç"]
e := [1,"è","é","ê","ë"]
i := [1,"ì","í","î","ï"]
o := [1,"ò","ó","ô","õ","ö"]
u := [1,"ù","ú","û","ü"]
CheckCtrlAlt := 1

#if CheckCtrlAlt ;check if Ctrl or Alt is Not down

*$a::
*$c::
*$e::
*$i::
*$o::
*$u::
key := StrReplace(A_ThisHotkey, "*$")
KeyWait, % key, T0.18 ;hold key more than 0.18 second to cycle
if ErrorLevel
{
	SetTimer, Reset, off ;Stop Reset
	;Hold key to cycle
	keyN := %key%.length() - 1
	keyi := %key%[1]
	Loop 1 {
		IfNotEqual, oldKey, % A_PriorKey
			oldKey := ""
		IfNotEqual, oldKey, % key
			keyi := 1
		keyi := (keyi > keyN ? 2 : keyi + 1)
		keyValue := %key%[keyi]
		if GetKeyState("Shift","P")
			StringUpper, keyValue, keyValue
		IfNotEqual, oldKey, % key
			Send, % "{Blind}" keyValue
		else
			Send, % "{Blind}{BackSpace}" keyValue
		%key%[1] := keyi
		Sleep, 300
	}until !GetKeyState(key,"P")
	oldKey := key
	KeyWait, % key
	SetTimer, Reset, 3000 ;Reset after 2 sec (Stop the cycle)
}
else
{
	if GetKeyState("Shift","P")
		StringUpper, key, key
	Send, {%key%}
	oldKey := ""
}
return

#if 

Reset:
oldKey := ""
SetTimer, Reset, off ;Stop Reset
return

~*Alt::
~*Ctrl::
CheckCtrlAlt := 0
CheckCtrlAltkey := StrReplace(A_ThisHotkey, "~*")
KeyWait, % CheckCtrlAltkey
if !GetKeyState(CheckCtrlAltkey,"P")
	CheckCtrlAlt := 1
oldKey := ""
return
/*
;Debug ###########
varCheck:
ToolTip, % "LastKey:" A_PriorKey "`noldKey:" oldKey ", key:" key "`nkeyN=" keyN ", keyi=" keyi ", keyValue =" %key%[keyi] "`n[a:"a[1] " ,e:" e[1] "]", 600, 0
return
;################
*/
:wave: There is always more than one way to solve a problem. ;)
User avatar
thelegend
Posts: 13
Joined: 23 Mar 2021, 15:29

Re: problems with diacritics

26 Mar 2021, 10:45

Rohwedder wrote:Perhaps?: J'ai besoin d'aide
It's funny how I didn't even think of asking my question in French. I'll ask there too, thanks!
YoucefHam wrote: You remined me of my time when I was typing my "memoire" for the university,
Hello YoucefHam! Your script is very clever! However, it doesn't solve my problem. I know where all my accents are, and I just want to be able to use them normally.

Also, I imagine/hope it works differently on your computer than mine, because your script makes me unable to write. Look how weird it gets when I type the exact same thing at the exact same speed.
GH2nNpnUuN.gif
GH2nNpnUuN.gif (318.58 KiB) Viewed 1526 times
And it's not like I have an old computer either : Ryzen 3 2200G 3.50 GHz + 16 gb of RAM!
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: problems with diacritics

26 Mar 2021, 11:38

try this :think:

Code: Select all

:*:à::lowercase a with grave
;in AHK `` = ` so type ``a to get à
:*:````a::lowercase a with grave
:wave: There is always more than one way to solve a problem. ;)
User avatar
thelegend
Posts: 13
Joined: 23 Mar 2021, 15:29

Re: problems with diacritics

08 Apr 2021, 10:47

YoucefHam wrote: try this :think:

Code: Select all

:*:à::lowercase a with grave
;in AHK `` = ` so type ``a to get à
:*:````a::lowercase a with grave
Thank you! (and sorry for the answering delay)

I thought of doing something similar… but I'd really rather have something more elegant. I want the problem to be FIXED, and not use a workaround that could potentially lead to other problems (since I'm not DESPERATE for the moment).

:ugeek:
lexikos
Posts: 9621
Joined: 30 Sep 2013, 04:07
Contact:

Re: problems with diacritics  Topic is solved

09 Apr 2021, 03:59

I was not able to reproduce this problem.

Is that the Canadian French keyboard layout?

Does it happen in all programs when you are not using the SC028::/Input/Send workaround?

When you type `a and it prints ``a, which keystrokes cause which characters to appear? Does pressing ` produce `` immediately?


The system provides a function named ToUnicodeEx (and an equivalent ToAsciiEx) for determining which characters are produced by a given combination of keyboard state and key codes. These functions include parameters for specifying the current "keyboard state" (which keys are pressed down or toggled on) and layout, but unfortunately nothing for specifying the pending state of any dead keys. Instead, calling ToUnicodeEx potentially causes it to internally buffer a dead key, so a subsequent call will produce something like à or `z. This means that naive use of ToUnicodeEx tends to have undesired effects such as stripping out accents altogether or causing them to double up. Over time AutoHotkey has been carefully altered and thoroughly tested to avoid undesired side-effects, such as causing the ` key to immediately print `` under some circumstances.

UWP apps (such as the Windows 10 Photos app and Settings app) are known to handle dead keys differently to the vast majority of desktop apps, so AutoHotkey (v1.1.27.05+) compensates based on whether a UWP window is focused. There are likely other apps which have custom handling for dead keys that AutoHotkey doesn't take into account, and I wouldn't be surprised if Word is one of them.

One possible explanation for ``a is that when you press sc028, something is calling ToUnicodeEx to determine which character corresponds to that key, and then passing the event on to the active window, which then calls ToUnicodeEx again. The first call returns the "dead key pending" value which is intended for the active window, then the second call (which is the first call by the active window) returns ``, because calling ToUnicodeEx twice is equivalent to pressing the key twice, even if it is called by two different processes.

Therefore, I recommend that you perform a "clean boot" and test with only AutoHotkey and Word running (or whatever program you normally see the problem with). You could also try safe mode, if Word works there.
User avatar
thelegend
Posts: 13
Joined: 23 Mar 2021, 15:29

Re: problems with diacritics

21 Apr 2021, 10:56

Dear Lexikos, thank you.

The problem was interference from another software, Breevy (www.16software.com/breevy/). It's a very nice text expansion software that I've been using for a number of years. I have thousands of abreviations on it.

I was contemplating the idea of migrating to AHK, at least in part, because of the nifty "#ifWinActive" function I could use to have certain hotstrings work only in specific contexts.

So yeah. The clean boot did the trick. Booting, than testing while opening programs one by one.

Thank you so much, and also thank you, YoucefHam and Rohwedder, for your willingness to help!!! :D :D :D

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mihai369 and 133 guests