Custom Keyboard Shortcuts for jumping to next word or end of line – Ubuntu 22.04

Hej there!
I switched from Mac to Linux currently and am still trying to figure out how to adjust some keyboard shortcuts.

For example I mapped Ctrl + Right arrow to End key in the settings by adding this as command:

zsh -c "xdotool getactivewindow key End"

That’s working as expected for one liners.
But in Mail Clients, Texteditors, etc. I’m not jumping to the end of the line but to the end of the whole text block.
However the End key sets the cursor to the end of the current line, not the whole block.
What am I missing here?
Of course same goes for Ctrl + Left which is mapped to Home key.

A second problem occured when I tried to map Alt + Left and Alt + Right to Ctrl + Left and Ctrl + Right. By pressing Alt + left I want to jump to the previous word and vice versa with Alt + Right:

zsh -c "xdotool getactivewindow key Control_L+Right"

When pressing Alt + Right nothing is happening.
I guess it’s not working because it’s referencing another custom shortcut.
Adding a short sleep 0.2s doesn’t do the trick:

zsh -c "sleep 0.2s && xdotool getactivewindow key Control_L+Right"

When I’m pressing Alt + Left now it’s just working, if I release the Alt key after releasing the Arrow key. The expected behaviour would be to move the cursor word wise just by keeping alt pressed and pressing the arrow keys…

Is there anyone having the same issue or someone who figured out a solution?

Many many thanks in advance!

Asked By: salat69

||

I managed to get all shortcuts working as expected by adding the –clearmodifiers flag. According to the xdotool manual:

Any command taking the –clearmodifiers flag will attempt to clear any active input modifiers during the command and restore them afterwards.

So I added the following command to my custom Alt+Shift+Left shortcut:

zsh -c "xdotool getactivewindow key --clearmodifiers Shift+Control_L+Left"

This solution solved the problem with Ctrl+Arrow keys jumping to beginning and end of paragraphs, too. Now the cursor jumps to the beginning and end of a single line.

Answered By: salat69