Text mapper
Creates a text-based mapping layer that triggers on certain key-sequences (hotstrings).
When activated, it erases the trigger sequence by emmiting backspace
key events and
then emmits the replacement text or calls a user-function.
import map2
# set the output keyboard layout
map2.default(layout = "us")
mapper = map2.TextMapper()
# map text to other text
mapper.map("hello", "bye")
# capitals and special letters are allowed
mapper.map("LaSeRs?", "lAsErS!")
# map to user-function
def greet(): print("Hello!")
mapper.map("greet", greet)
# ❌ This won't work, writers can only output keys contained
# in the output keybarod layout.
# Since we specified the 'us' layout above, we can't map to kanji directly.
mapper.map("usagi", "兎")
# ✅ we can instead use a virtual writer for writing special characters.
# note: not all environments support virtual writers
virtual_writer = map2.VirtualWriter()
def write_special(text):
def fn(): writer_virtual.send(text)
return fn
mapper.map("usagi", write_special("兎"))
Supported on:
- ✅ Hyprland
- ✅ X11
- ✅ Gnome (wayland)
- ✅ KDE plasma (wayland)
Options
model
string?
Sets the XKB keyboard model.
layout
string?
Sets the XKB keyboard layout.
variant
string?
Sets the XKB keyboard variant.
options
string?
Sets the XKB keyboard options.
Methods
map(from, to)
Maps a text sequence to a different text sequence or user-function.
- from: key_sequence
- to: key_sequence | () -> void