reddit / emacs

Remap ctrl to caps lock only when emacs is running, on linux

Dumb-Ptr · 2022-03-04 17:36
In windows I did this using an AutoHotKey script that chekced if an emacs' instance was running, and if so, it would make tha caps lock a ctrl key, but in linux I have no idea how to do it. I know how to remap a key for the whole system, just not for only an emacs instance... any idea?
Deleted_1-year-ago · 2022-03-04 18:02
Depending on your Desktop Enviorment, you will be able to set commands on startup. You only really need to put '''setxkbmap -option ctrl:swapcaps''' as a startup command asuming you're using Xorg.
Dumb-Ptr · 2022-03-04 18:14
yes I'm using xorg with dwm. I just use stxkbmap in the .xinitrc? Besides, it's still going to apply this change system-wise, which is better than nothing, but not ideal
Deleted_1-year-ago · 2022-03-04 20:49
Oh, a fellow wm autist I see. I remember dwm being a little bit of a pain to set autostart applications, I think there was a patch that executed a script on startup. And by the way, the setxkbmap is not global, just session-wide in the current user (you don't need to call 'sudo' for it), so no worries irreversably fucking up your keyboard.
[deleted] · 2022-03-04 21:43
In the distant past I remapped my Caps Lock key to Esc. I think I was experimenting with hard drugs and vim at the time.
SlowValue · 2022-03-05 03:28
There are several window managers, which are capable of remapping keys on a per application basis (StumpWM, FVWM, EXWM and others). On StumpWM the feature is called`define-remapped-keys`. On FVWM the module implementing this functionality is called `FakeKeypress`. I do not know if dwm implements something like this. There might be programs which are also capable to do this, but I could imagine they pose a security risk, since they have to intercept all key input.