AutoCorrect for AHK is not working for Unicode languages

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 09:39

Hi,
I heavily use the AutoCorrect feature of MS Word but it works only in MS Word. I was looking for a script that would enable me to use the AutoCorrect feature in web browsers. I found the AutoCorrect feature of "AutoCorrect for AHK-L.ahk" works nicely for English but it does not work for Unicode languages such as Bengali. I have added some Bengali words for auto-correction in the attached file. It does not work for Bengali but still works for English.

I am using Windows 7, 64 bit OS. I have tried with AutoHotKey v1.1.22.09 both 32 bit and 64 bit versions but neither works.

Could anybody help me to make it work for Bengali (typed in Unicode)? I would really appreciate it! Thank you!
Attachments
AutoCorrect for AHK-L - Bengali.ahk
(254.45 KiB) Downloaded 98 times
sendlevel

Re: AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 12:20

I think it may have something to do with how you type the Bengali characters? I just tried it by switching the keyboard layout. What happens if you just write a simple script and run that as a new script - so just create a one line script with one hotstring in it and run that.
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 13:12

sendlevel wrote:I think it may have something to do with how you type the Bengali characters? I just tried it by switching the keyboard layout. What happens if you just write a simple script and run that as a new script - so just create a one line script with one hotstring in it and run that.
Thank you for your reply. I type Bengali characters with a Tavultesoft Keyman Keyboard. According to your suggestion, I just created a one line script with one hotstring in it and ran it but it did not work for Bengali. I added a second word in English and the English autocorrect worked.

For example:
::bd::Bengali - works nicely.
::কখ::কখনো - do not works.
::cd::কখনো - works nicely!

In the 3rd example above, English input and Bengali output works but Bengali input and Bengali output does not work. It is something with the input or typing but I am unable to solve this issue. Is there any way to solve this issue?
sendlevel

Re: AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 13:35

It may be as easy as adding #Hotstring NoMouse to the top of your script if you use a virtual keyboard. Or you could look into https://autohotkey.com/docs/commands/_InputLevel.htm and https://autohotkey.com/docs/commands/SendLevel.htm to see if that helps. If that doesn't do it, you could try using the Input command, demo script here https://autohotkey.com/board/topic/7102 ... /?p=450031
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 14:00

Hi sendlevel, thank you for your reply. I added #Hotstring NoMouse at the top of the script but it is not working.

SendLevel is not working for Bengali, but it is working for English.

Input Level is showing an error message - "Note: The hotkey *আ will not be activate because it does not exist in the current keyboard layout."

I could not understand the demo script for Input command. I am not an expert of AHK.

Is there any other ways to make it work? May be the clue is: "The hotkey *আ will not be activate because it does not exist in the current keyboard layout." AHK can not recognize the Bengali alphabets from the current keyboard layout.
sendlevel

Re: AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 15:00

I posted two examples here (guests can't post non-English characters it seems) - you will have to remove the code /code blocks from the code to run it of course,
there are two scripts. One with Inputlevel and one with Input and you'll have to fix the URL to as guests can't post urls either it seems

pastebin . com / qv5A6Sng
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoCorrect for AHK is not working for Unicode languages

25 Dec 2015, 20:46

Please read Script File Codepage.

In short: Save your script as UTF-8 with byte order mark.
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 03:00

lexikos wrote:Please read Script File Codepage.

In short: Save your script as UTF-8 with byte order mark.
Hi Lexikos,
Thanks a lot for your reply.
When I save the file as UTF-8:
::cd::কখনো - executes but the Bengali word কখনো shows with peculiar characters.

When I save the file as UTF-8 with BOM:
::cd::কখনো - executes nicely and the Bengali word কখনো shows with correct Bengali characters.

But, when I use any Bengali alphabet as input, it does not execute. For example:
::কখ::কখনো - does not execute.

The problem is, AHK is not recognizing Bengali characters as inputs. May be it has something to do with the Keyboard input. Is there any way to tell the AHK to read the Bengali characters from the file/screen, not from the keyboard input?
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 03:09

sendlevel wrote:I posted two examples here (guests can't post non-English characters it seems) - you will have to remove the code /code blocks from the code to run it of course,
there are two scripts. One with Inputlevel and one with Input and you'll have to fix the URL to as guests can't post urls either it seems

pastebin . com / qv5A6Sng
Hi sendlevel,

Thanks a lot for all your time for me. You wrote, "This example script works for me with Inputlevel, here I remap a to ক and when I type "a" I get a "ক", if follow that by a space I get ন". This also works for me but the problem is, I am typing with a Bengali Keyboard and I can not input "a" or other English alphabets with this keyboard. I am looking for something that would recognize the Bengali characters as inputs while I am typing with a Bengali Keyboard. I do not know how MS Word does this but it is working perfectly with MS Word. MS Word recognizes the Bengali characters as inputs and do the autocorrect nicely. The only problem is it works inside MS Word ONLY and I can not use it for other programs such as Internet Browsers.

However, thanks a lot for all your help.
sendlevel

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 05:10

I've just downloaded Tavultesoft Keyman Keyboard (there is a free version to try) and indeed AutoHotkey doesn't see the Bengali text but keeps seeing the English key (character) you pressed, so in case of the 'a' above it sees the 'a' and not the remapped character or typed text. I confirmed this via the Keyboard history and also by adding a tooltip to the Loop+Input script - so Keyman Keyboard uses a technique that AHK can't see.

Apart from the on screen keyboard is there a particular reason to keep on using Keyman? From what I can tell it isn't that difficult to use AutoHotkey to do the same as it is simply a bunch of remapped keys, and if you do decide to use AutoHotkey only, the hotstrings will work as demonstrated.

So Keyman to type + AHK hotstrings doesn't work.
Using AHK to type + AHK hotstrings does work.

It would be relatively easy to display a similar image as the Keyman on screen keyboard using AHK* and also have a quick toggle hotkey to switch between languages (a simpel #If will do).

* You can simply make a screengrab of the keyman keyboard and use that image in a transparent AHK Gui https://autohotkey.com/docs/commands/Gu ... tm#Picture and https://autohotkey.com/docs/commands/Wi ... TransColor
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 05:32

Thanks a Million, sendlevel! After your last message, I was also started thinking about using AHK to type Bengali in your showed way. I was just concerned how to code to display a couple of hundred conjunct characters in Bengali. Can you read Bengali? If you can read Bengali then you would know what I am talking about.

I am not at all concerned about the on-screen Keyboard. I made a Keyman keyboard by myself and I memorized it completely. I do not need the on-screen keyboard.

I need to learn how to group characters/alphabets in AHK so that I can convert my Keyman keyboard to AHK Keyboard.

Thanks a Million for showing me the way!
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 05:40

Bullex wrote:Thanks a lot for your reply.
You're welcome, and my apologies for not reading past the first post before replying. I see now that you already had Bengali output working.
SendLevel is not working for Bengali, but it is working for English.
SendLevel and #InputLevel are only relevant for keyboard/mouse events generated by AutoHotkey scripts.
Is there any way to tell the AHK to read the Bengali characters from the file/screen, not from the keyboard input?
No. Hotkeys and hotstrings work by monitoring keyboard events.

You can read characters from a file using one of various methods and replace text using one of various methods, but you would obviously have to save the text to file in the first place. Most of the time, whatever you've just typed isn't in any file, and even if it is, AutoHotkey has no way of knowing.

There is no reliable, universal method to read text from the screen or detect the text insertion point.
I need to learn how to group characters/alphabets
If you need any pointers, just post an example of how this grouping works. :)
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 06:02

lexikos wrote:If you need any pointers, just post an example of how this grouping works. :)
Please have a look at my Keyman Keyboard below as an example of how this grouping works:
.......................
c Bangla(Bengali) Unicode Keyboard for Keyman 8.0

CAPS ALWAYS OFF

begin Unicode > use(Main)

store( &Copyright ) "Unicode Keyman Keyboard"
store( &Message ) "Free for all"

store(english) "ABCDEFGHIJKLMNOPQRSTVWXYZ"

store(english_vowel) "AaEeIiOoUu"

Store(vowel) U+0986 U+0987 U+0988 U+0989 U+098A U+098F U+0990 \
U+0993 U+0994 U+0985 U+098B U+098C

store(matra) U+09BE U+09BF U+09C0 U+09C1 U+09C2 U+09C7 U+09C8 \
U+09CB U+09CC U+09C3 U+09C4 U+09D7

store(autovowel) "aiIuUeEoO"

store(consonant) U+0995 U+0996 U+0997 U+0998 U+0999 \
U+099A U+099B U+099C U+099D U+099E U+099F U+09A0 U+09A1 \
U+09A2 U+09A3 U+09A4 U+09A5 U+09A6 U+09A7 U+09A8 U+09AA \
U+09AB U+09AC U+09AD U+09AE U+09AF U+09B0 U+09B2 U+09B6 \
U+09B7 U+09B8 U+09B9 U+09DC U+09DD U+09DF U+09F0 U+09F1 \
U+200C U+200D U+25CC

store(allfont) U+0985 U+0986 U+0987 U+0988 \
U+0989 U+098A U+098B U+098C U+098F U+0990 \
U+0993 U+0994 U+0995 U+0996 U+0997 U+0998 U+0999 \
U+099A U+099B U+099C U+099D U+099E U+099F U+09A0 U+09A1 \
U+09A2 U+09A3 U+09A4 U+09A5 U+09A6 U+09A7 U+09A8 U+09AA \
U+09AB U+09AC U+09AD U+09AE U+09AF U+09B0 U+09B2 U+09B6 \
U+09B7 U+09B8 U+09B9 U+09DC U+09DD U+09DF U+09F0 U+09F1 \
U+200C U+200D U+25CC U+09BE U+09BF U+09C0 U+09C1 U+09C2 U+09C3 \
U+09C4 U+09C7 U+09C8 U+09CB U+09CC U+09D7

group( Main ) using keys
+ "`" > U+09D7
+ "0" > U+09E6
+ "1" > U+09E7
+ "2" > U+09E8
+ "@" > "@"
+ "3" > U+09E9
+ "#" > U+09C3
+ "$" > U+09F3
+ "4" > U+09EA
+ "5" > U+09EB
+ "6" > U+09EC
+ "7" > U+09ED
+ "&" > U+099E
+ "8" > U+09EE
+ "*" > U+09CE
+ "9" > U+09EF
+ "^" > U+098B
+ "_" > "_"
+ "+" > U+201D
+ "=" > U+201C
+ "A" > U+0985
+ "a" > U+0986
+ "B" > U+09AD
+ "b" > U+09AC
+ [RALT K_B] > U+09F1
+ "C" > U+099B
+ "c" > U+099A
+ "D" > U+09A2
+ "d" > U+09A1
+ "E" > U+0990
+ "e" > U+098F
+ "F" > U+09A5
+ "f" > U+09A4
+ "G" > U+0998
+ "g" > U+0997
+ "H" > U+09B9
+ [RALT K_H] > U+09BD
+ "h" > U+09CD
+ "I" > U+0988
+ "i" > U+0987
+ "J" > U+09AF
+ "j" > U+099C
+ "K" > U+0996
+ [SHIFT RALT K_K] > U+098C
+ [RALT K_K] > U+09E2
+ "k" > U+0995
+ "L" > U+099D
+ [RALT K_L] > U+09E3
+ "l" > U+09B2
+ [SHIFT RALT K_L] > U+09E1
+ "M" > U+0999
+ "m" > U+09AE
+ "N" > U+09A3
+ "n" > U+09A8
+ "O" > U+0994
+ "o" > U+0993
+ "P" > U+09AB
+ "p" > U+09AA
+ "Q" > U+0983
+ "q" > U+0995 U+09CD U+09B7
+ "R" > U+09DC
+ [RALT K_R] > U+09F0
+ "r" > U+09B0
+ "S" > U+09B6
+ "s" > U+09B8
+ "T" > U+09A0
+ [SHIFT RALT K_T] > U+09E0
+ "t" > U+099F
+ [RALT K_T] > U+09C4
+ "U" > U+098A
+ "u" > U+0989
+ "V" > U+09A7
+ "v" > U+09A6
+ "W" > U+0981
+ "w" > U+09B0 U+09CD
+ "X" > U+098B
+ "x" > U+09B7
+ "Y" > U+09DD
+ "y" > U+09DF
+ "Z" > U+0982
+ "z" > U+09CD U+09AF
+ '{' > '{'
+ '[' > '['
+ '}' > '}'
+ ']' > ']'
+ '"' > U+2019
+ [SHIFT RALT K_QUOTE] > U+201C
+ "'" > U+2018
+ [RALT K_QUOTE] > U+201D
+ ":" > ":"
+ [SHIFT RALT K_COLON] > ":"
+ "<" > "<"
+ [SHIFT RALT K_COMMA] > "<"
+ ">" > "."
+ "." > U+09F7
+ [SHIFT RALT K_PERIOD] > "."
+ "\" > [K_LEFT]
+ [RALT K_BKSLASH] > U+0965
+ "|" > "\"
+ [SHIFT RALT K_BKSLASH] > "|"
+ "/" > "/"
+ [SHIFT K_oE2] > U+09F0
+ [K_oE2] > U+09F1

c Consonat + autovowel i
any(consonant) + "i" > context U+09BF
any(consonant) U+09BF + "i" > index(consonant,1) U+0987
any(consonant) U+0987 + "i" > index(consonant,1) U+09BF U+0987
c Consonat + autovowel I
any(consonant) + "I" > context U+09C0
any(consonant) U+09C0 + "I" > index(consonant,1) U+0988
any(consonant) U+0988 + "I" > index(consonant,1) U+09C0 U+0988
c Consonat + autovowel e
any(consonant) + "e" > context U+09C7
any(consonant) U+09C7 + "e" > index(consonant,1) U+098F
any(consonant) U+098F + "e" > index(consonant,1) U+09C7 U+098F
c Consonat + autovowel E
any(consonant) + "E" > context U+09C8
any(consonant) U+09C8 + "E" > index(consonant,1) U+0990
any(consonant) U+0990 + "E" > index(consonant,1) U+09C8 U+0990
c Consonat + autovowel u
any(consonant) + "u" > context U+09C1
any(consonant) U+09C1 + "u" > index(consonant,1) U+0989
any(consonant) U+0989 + "u" > index(consonant,1) U+09C1 U+0989
c Consonat + autovowel U
any(consonant) + "U" > context U+09C2
any(consonant) U+09C2 + "U" > index(consonant,1) U+098A
any(consonant) U+098A + "U" > index(consonant,1) U+09C2 U+098A
c Consonat + autovowel o
any(consonant) + "o" > context U+09CB
any(consonant) U+09CB + "o" > index(consonant,1) U+0993
any(consonant) U+0993 + "o" > index(consonant,1) U+09CB U+0993
c Consonat + autovowel O
any(consonant) + "O" > context U+09CC
any(consonant) U+09CC + "O" > index(consonant,1) U+0994
any(consonant) U+0994 + "O" > index(consonant,1) U+09CC U+0994
c Consonat + autovowel aa kar
any(consonant) + "a" > context U+09BE
any(consonant) U+09BE + "a" > index(consonant,1) U+0986
any(consonant) U+0986 + "a" > index(consonant,1) U+09BE U+0986
c Join key
any(consonant) any(consonant) + "h" > index(consonant,1) U+09CD index(consonant,2)
c chondrobindu
any(consonant) U+0981 + any(autovowel) > index(consonant,1) index(matra,3) U+0981
c Ref
any(allfont) any(allfont) + "w" > index(allfont,1) U+09B0 U+09CD index(allfont,2)
any(allfont) any(allfont) any(matra) + "w" > index(allfont,1) U+09B0 U+09CD index(allfont,2) index(matra,3)

c The End
................

Thank you!
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: AutoCorrect for AHK is not working for Unicode languages

26 Dec 2015, 18:45

So... how does the grouping work? This appears to be a configuration file of some sort, perhaps defining the groups. I don't know how to interpret it, because I don't know how the grouping works. I can make guesses, but I may be wrong. I have no clue whatsoever about "context" and "autovowel".

Generally, your options are:
  • Hotkeys/remapping for single keys and key-combinations (hold x and press y).
  • Hotstrings or the Input command for sequences of characters.
  • (Advanced): Hook the keyboard and process all the keyboard events yourself.
You can do a lot just by combining hotkeys with other commands/functions and logic. For instance, Dynamic RegEx Hotstrings allow you to define a kind of hotstring using patterns instead of static text as the trigger. This works by using hotkeys to monitor your typing.

In general if you want a hotstring to consider characters produced by another hotkey, hotstring or remapping, you need to use #InputLevel or SendLevel (with a higher level than the hotstring). This is probably a bit difficult to understand without an example, so...:

Code: Select all

SendMode Input

:?*C:k::
SendLevel 1  ; Default is #InputLevel 0
Send ক
return

:?*:কক::খ   ; kk
(I'm fairly certain this isn't exactly what you want, but perhaps it will help.)
Bullex
Posts: 11
Joined: 25 Dec 2015, 09:23

Re: AutoCorrect for AHK is not working for Unicode languages

27 Dec 2015, 03:34

Thank you, lexicos! I need to read and work a lot to fully understand how to create a Keyboard and combine autocorrect by using AHK. Just to explain grouping to you, there are mainly three types of alphabets in Bengali - Vowel, Consonant and Matra (this is like accent characters in some European languages). We need to use some logic to create a fourth group of alphabet namely conjunct characters. We make different groups for Vowel, Consonant and Matra so that we can use logic for the entire group.

My original intention was to create an Autocorrect script for Bengali and that seems not possible by using AHK because AHK can not recognize Bengali inputs. Is there any other software/script/program that can help achieve that goal? I tried most of the commercially available software found in internet and it seems that none of them support Bengali/Unicode alphabets!!!
sendlevel

Re: AutoCorrect for AHK is not working for Unicode languages

27 Dec 2015, 04:09

Start of simple and expand on it, perhaps this example will get you going. You can do the simple remaps first, then tackle the combinations modifier + key. Below are only standard hotkeys & hotstrings, but as Lexikos (with K) mentioned there are more complex methods using regular expressions so you don't have to setup dozens of hotstrings but can combine groups by defining a clever regular expression and process it. But start of simple. When AHK sends the Bengali characters I'm sure your Bengali hotstrings will work.

Code: Select all

#UseHook
SetBatchLines, -1
SetKeyDelay, -1
SendMode, Input

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

; ----------
; Setup
Bengali:=0
F12::reload

#Space:: ; turn the remapping on/off
Bengali:=!Bengali
Return

; ----------
; Bengali specific hotkeys & hotstrings due to #If below
#If Bengali

; one to one remaps
#InputLevel 1
1::a
2::b

; modifier remaps
!3:: Send c ; alt+3

; ----------
; Standard hotstrings
; ----------

::ab::456
::bc::879

; ----------
; you can be more flexible using Dynamic RegEx Hotstrings
; "(py)i\s" -> which means a p or y followed by an i followed by a space, tab or enter

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: jaka1, Spawnova and 264 guests