This is my attempt to build an input method editor using only Rust. It's not the first, and definitely not the last.
The goal is to create an input method editor that allows the user to type Vietnamese text on the computer. Using either VNI or TELEX method. Other than that, no other feature are planned.
How to install
Currently, we're still in a very early stage, hence, no pre-built binaries are provided.
But you can get the source code and compile it yourself, it's very easy:
- Get the latest stable version of the Rust compiler (see here)
- Install the cargo-bundle extension, this is necessary for bundling macOS apps
- Checkout the source code of the gõkey project
git clone https://github.com/huytd/goxkey && cd goxkey
- Run the bundle command:
After this, you'll find the
Gõ Key.app file in the
Currently, only macOS is supported. Windows and Linux can be supported later but it's not in the roadmap. If you're on these OSes, any help would be greatly appreciated!
This project will only focus on the input handling logic, and provide a frontend for the input engine (
The following diagram explains how
goxkey communicates with other components like OS's input source and
INPUT LAYER +------------------+ FRONTEND ENGINE | macOS | [d,d,a,a,y] +---------+ "ddaay" +-------+ | +- CGEventTap | -----------> | goxkey | ----------> | vi-rs | | | +---------+ +-------+ | Linux (TBD) | | ^ | | Windows (TBD) | | | "đây" | +------------------+ | +--------------------+ | | (send_key) v Target Application
On macOS, we run an instance of
CGEventTap to listen for every
keydown event. A callback function will be called on every keystroke. In this callback, we have a buffer (
TYPING_BUF) to keep track of the word that the user is typing. This buffer will be reset whenever the user hit the
The input engine (
vi-rs) will receive this buffer and convert it to a correct word, for example:
vieetj will be transformed into
The result string will be sent back to
goxkey, and from here, we will perform an edit on the target application. The edit is done using the BACKSPACE technique. It's unreliable but it has the benefit of not having the pre-edit line, worth it.
To get yourself familiar with IME, there are some good article on the topic:
- Vietnamese Keyboard Engine with Prolog, lewtds
- Ước mơ bộ gõ kiểu Unikey trên Linux, lewtds
- Vấn đề về IME trên Linux, zerox-dg
- Bỏ dấu trong tiếng Việt, zerox-dg
- Chuyện gõ tiếng Việt trên Linux, huytd
Local development setup
To setup the project locally, first, checkout the code and run the install script to have all the Git hooks configured:
$ git clone https://github.com/huytd/goxkey && cd goxkey $ make setup
After this step, you can use the
make commands to run or bundle the code as needed:
$ make run # or $ make bundle