You are not logged in.

#1 2024-06-10 08:28:09

hat082
Member
Registered: 2024-06-10
Posts: 3

Issue with Mapping Caps_Lock to Escape Key via xmodmap

**Title:** Issue with Mapping Caps_Lock to Escape Key in Vim

**Body:**

Hello Arch Linux community, I'm a complete newbie to arch ;-;

I'm trying to remap the Caps_Lock key to function as an Escape key to improve my navigation in Vim. I don't really need the Caps_Lock key anymore, so i didn't swap the keys.

The `.Xmodmap` file is really basic:
   ```
   keycode 66 = Escape NoSymbol Escape NoSymbol
   ```
However, I'm experiencing an issue where the Caps_Lock key sometimes behaves as if it's both Escape and Caps_Lock. To diagnose the problem, I used the following command to print the keypresses in a more readable format:

```
xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'
```

The output I get is inconsistent and sometimes shows the Caps_Lock key as Escape:

```
38  a
66  Escape
38  A
66  Escape
38  a
9   Escape
38  a
9   Escape
38  a
```

Interestingly, the problem seems to resolve itself after a re-login (sometimes) , but manually running `xmodmap .Xmodmap` during a session doesn't fix the issue.

I'm not sure what's causing this behavior, and I could use some help diagnosing the problem. Any suggestions or insights would be greatly appreciated.

Thank you!

Offline

#2 2024-06-10 12:49:49

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Issue with Mapping Caps_Lock to Escape Key via xmodmap

That's the wrong approach.  Just `setxkbmap -option caps:escape`, or prior to starting X `export XKB_DEFAULT_OPTIONS=caps:escape`.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2024-06-10 14:09:05

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: Issue with Mapping Caps_Lock to Escape Key via xmodmap

Or https://wiki.archlinux.org/title/Xorg/K … tion_files
nb. that setxkbmap is transient and will get lost when the keyboard (logically) re-attaches what can happen in response to an S3 cycle or USB autosuspend (let alone the hardware specific issues of wireless keyboards) so I'd opt for the environment or the config file.

Online

#4 2024-06-11 07:34:33

hat082
Member
Registered: 2024-06-10
Posts: 3

Re: Issue with Mapping Caps_Lock to Escape Key via xmodmap

Sorry for the delayed reply..

Trilby wrote:

That's the wrong approach.  Just `setxkbmap -option caps:escape`, or prior to starting X `export XKB_DEFAULT_OPTIONS=caps:escape`.

Thank you this worked!

I'm curious if it's possible to configure the Caps Lock key to act as Escape when tapped and as Left Ctrl when held down. I understand this might not be essential, but I'm exploring my options.

Thank you for your guidance.

Offline

#5 2024-06-11 07:39:44

hat082
Member
Registered: 2024-06-10
Posts: 3

Re: Issue with Mapping Caps_Lock to Escape Key via xmodmap

seth wrote:

Or https://wiki.archlinux.org/title/Xorg/K … tion_files
nb. that setxkbmap is transient and will get lost when the keyboard (logically) re-attaches what can happen in response to an S3 cycle or USB autosuspend (let alone the hardware specific issues of wireless keyboards) so I'd opt for the environment or the config file.

Thanks for your suggestion! Those sounds like really advanced topics.. especially for a noob like me..

If i use setxkbmap, the caps_lock key stops working if I open neovim? But if I set the environment variable, this bug doesn't occur. I don't really understand why this is the case but I guess I'll be sticking to the second option.

Last edited by hat082 (2024-06-11 07:45:54)

Offline

#6 2024-06-11 12:10:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: Issue with Mapping Caps_Lock to Escape Key via xmodmap

hat082 wrote:

I'm curious if it's possible to configure the Caps Lock key to act as Escape when tapped and as Left Ctrl when held down.

Not through xkb settings, no.  The available options can be found in `man xkeyboard-config`; the most relevant options are under the OPTIONS section "Caps Lock  behavior" subsection.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#7 2024-06-11 13:10:58

seth
Member
Registered: 2012-09-03
Posts: 59,084

Re: Issue with Mapping Caps_Lock to Escape Key via xmodmap

For different behavior on "empty" release of a modifier (ctrl) you'd need a shortcut deamon that can discrimintate that way (i think xbindkeys can via the release modifier, but would have to test that) and then bind that action to a shortcut that fires "xdotool key escape" or so.

Online

Board footer

Powered by FluxBB