Hyprland version
0.54.3
Describe your issue / feature…
Not really sure if this is even possible, but what I’m basically looking to do is to replace a character I have typed in with a different character, retroactively, without having to delete the previous character manually, in any app or program inside of Hyprland where there is an input box. For example, I type “hello”, but want to change “o” to something else. The normal way to do it is to just press backspace once, to remove the “o” and type in the new character. However, what I want to do is after typing “hello”, if the caret is to the right of the “o”, then press some keybinding to run a script that will replace the “o” with “ò” or “ö” or “O” or “_” or whatever character I configure it to be. Obviously, this example is poor since just using backspace makes more sense. However, there are situations where this makes more sense, such as:
You accidently had Caps Lock enabled and were looking at your keyboard while typing, and you ended up typing quite a lot. Instead of deleting everything and retyping it in lowercase, you run a script via keybinding that selects all the uppercase letters the right left of the caret, and then returns sentence case.
You accidently had a different keyboard layout enabled, Spanish for instance, and you want to remap all of the characters you typed to English.
However, I’m not so interested with the most practical solutions to the aforementioned examples as I am in “replacing text retroactively relative to the position of the cursor” - if this can even be done.
Here is what I tried so far:
I downloaded ydotool and wl-clipboard and created a script which runs whever I press the keybind I assigned to it in hyprland.conf.
#!/bin/bash
# Select previous character
ydotool key 29:1 42:1 105:1 # ctrl+shift+left (press)
ydotool key 105:0 42:0 29:0 # release
# Copy
ydotool key 29:1 46:1 # ctrl+c
ydotool key 46:0 29:0
sleep 0.03
char=$(wl-paste)
case "$char" in
a) new="á" ;;
e) new="é" ;;
i) new="í" ;;
o) new="ó" ;;
u) new="ú" ;;
A) new="Á" ;;
E) new="É" ;;
I) new="Í" ;;
O) new="Ó" ;;
U) new="Ú" ;;
*) exit 0 ;;
esac
# Delete original
ydotool key 14:1
ydotool key 14:0
# Paste new
echo -n "$new" | wl-copy
ydotool key 29:1 47:1 # ctrl+v
ydotool key 47:0 29:0
All this unfortunately does is copy the character to the left of the caret and add it to the clipboard.
I did some research and from what I understand, doing this kind of input manipulation doesn’t work nicely with Hyprland.
Any ideas or suggestions?