Linux turn off caps lock

How to disable caps lock in Linux

The caps lock key is a vestige from older times. It is completely useless today and extremely irritating because it gets turned on by mistake while using programs like Vim. It is a good idea to turn it off completely by disabling it.

The setxkbmap program can be used to disable caps lock completely in all desktop environments and window managers by mapping it to the Ctrl key:

$ /usr/bin/setxkbmap -option '' -option 'ctrl:nocaps'

To apply this setting every time you login to any desktop environment, add the above line to your ~/.profile file. Log out and login to see the effect of this option.

Other methods to disable caps lock that I used to try earlier are given below:

KDE

  • In newer versions of Kubuntu: System Settings → Input Devices → Keyboard
  • In older versions of Kubuntu: System Settings → Hardware → Keyboard → Advanced.
  • Enable Configure keyboard options and under the tree of options choose Caps Lock is disabled.

Ubuntu 14.04

Install the GNOME Tweak Tool:

$ sudo apt-get install gnome-tweak-tool

Open it by typing Tweak Tool in the Dash. Choose Typing → Caps Lock key behavior. Confusingly, it is shown as Disabled. But this means that any customization on that is disabled. In the dropdown choose Caps Lock is disabled option and you are done!

Ubuntu 12.04

Open Keyboard Layout and click on the keyboard layout you are using, for example English (US). Click on Options → Caps Lock key behavior and choose Caps Lock is disabled.

Источник

How do I turn off Caps Lock (the lock, not the key) by command line?

For some reason my laptop is stuck in Caps Lock. I have the Caps Lock key mapped by xmodmap to hyper_l , so I don’t have a caps_lock key to turn it off. Is there a way I can turn it off by command line? It would be nice if I could reset the lock state without resetting my computer, especially for future reference. This has happened before, but I would like to know now how to do it properly this time.

Читайте также:  Visual studio remote linux

[echo -e «$(dumpkeys | grep ^keymaps)\nkeycode 58 = Escape» | sudo loadkeys][1] [Adding the following line to .profile or .bash_profile should disable caps lock:][2] [xmodmap -e «remove lock = Caps_Lock»][3] [1]: askubuntu.com/questions/43986/… [2]: askubuntu.com/questions/43986/… [3]: askubuntu.com/questions/43986/…

there is a bug there. there is no command currently to do that. you could use setleds +caps or -caps but its not working. the only thing u can do is already answered. you can remap caps

5 Answers 5

I don’t know of any command line tool for that in Ubuntu. (For Num Lock, there is numlockx .) Here’s a one-liner that you can copy-paste into a terminal window:

python -c 'from ctypes import *; X11 = cdll.LoadLibrary("libX11.so.6"); display = X11.XOpenDisplay(None); X11.XkbLockModifiers(display, c_uint(0x0100), c_uint(2), c_uint(0)); X11.XCloseDisplay(display)' 

Here it is again in a more expanded form. We use the Python ctypes library to call C functions from the X library directly. The function XkbLockModifiers changes the state of the keyboard locks, on the core keyboard ( XkbUseCoreKbd = 0x0100), affecting Caps Lock (2), setting it to 0 (off).

#!/usr/bin/env python from ctypes import * X11 = cdll.LoadLibrary("libX11.so.6") display = X11.XOpenDisplay(None) X11.XkbLockModifiers(display, c_uint(0x0100), c_uint(2), c_uint(0)) X11.XCloseDisplay(display) 

If you have a stuck modifier, change 2 to the mask of the modifiers you want to turn off. The modifiers are 1=Shift, 2=Lock (Caps Lock), 4=Control, 8=Mod1, 16=Mod2, 32=Mod3, 64=Mod4, 128=Mod5. Run xmodmap -pm to see what Mod1 through Mod5 correspond to. For example, to turn off all modifiers, call X11.XkbLockModifiers(display, c_uint(0x0100), c_uint(255), c_uint(0)) . To turn on Num Lock which is on Mod2 and at the same time turn off Caps Lock, call X11.XkbLockModifiers(display, c_uint(0x0100), c_uint(2 | 16), c_uint(16)) .

Here’s a C version if you want to make a small binary instead of invoking Python. Compile with gcc -O -Wall -o caps_lock_off caps_lock_off.c -lX11 , with the packages build-essentials and libx11-dev installed.

#include #include #include int main() < Display *display = XOpenDisplay(NULL); if (display == NULL) < fprintf(stderr, "Couldn't open display\n"); return 2; >Bool sent = XkbLockModifiers(display, XkbUseCoreKbd, LockMask, 0); if (!sent) < fprintf(stderr, "Couldn't send LatchLockState\n"); return 1; >#ifdef REPORT_STATE XkbStateRec xkb_state; Status status = XkbGetState(display, XkbUseCoreKbd, &xkb_state); if (status) < fprintf(stderr, "XkbGetState returned %d\n", status); return 1; >printf("state.group=%02x\n", xkb_state.group); printf("state.locked_group=%02x\n", xkb_state.locked_group); printf("state.base_group=%02x\n", xkb_state.base_group); printf("state.latched_group=%02x\n", xkb_state.latched_group); printf("state.mods=%02x\n", xkb_state.mods); printf("state.base_mods=%02x\n", xkb_state.base_mods); printf("state.latched_mods=%02x\n", xkb_state.latched_mods); printf("state.locked_mods=%02x\n", xkb_state.locked_mods); printf("state.compat_state=%02x\n", xkb_state.compat_state); printf("state.grab_mods=%02x\n", xkb_state.grab_mods); printf("state.compat_grab_mods=%02x\n", xkb_state.compat_grab_mods); printf("state.lookup_mods=%02x\n", xkb_state.lookup_mods); printf("state.compat_lookup_mods=%02x\n", xkb_state.compat_lookup_mods); printf("state.ptr_buttons=%02x\n", xkb_state.ptr_buttons); #endif int err = XCloseDisplay(display); if (err) < fprintf(stderr, "XCloseDisplay returned %d\n", err); return 1; >return 0; > 

Also possibly of interest is a way to temporarily ignore Caps Lock:

Читайте также:  Linux где лежат службы

After this, Caps Lock will effectively be permanently off, until you reenable it with xkbset nullify -lock .

Источник

How do I disable or change the caps lock key on my keyboard?

We have ergonomic keyboards at work which I’m not entirely used to. I seem to keep hitting the capslock key while I’m in vim and it’s starting to annoy. How can I disable this key, and or change to to be another key?

Related: Remapping caps-lock to escape, and menu to compose, on the linux console. Do you want this only in X, or in your OS (which?)’s console?

4 Answers 4

The quick and dirty way to disable it is with xmodmap :

The next question is what would you like to do with it? I usually make it either a Ctrl key:

$ xmodmap -e 'keycode 66 = Control_L' 

Depending on your DE/WM, there is likely a way to do this in the GUI configuration. For example Gnome has a «keyboard layout» option on the control pannels with an options tab that includes several similar layout modifications.

The setting to disable your capslock is

This would be placed in your .xmodmap file.

Another option — to disable it temporarily, you can use a setxkbmap option:

setxkbmap -option ctrl:nocaps 

and then, to restore normal behavior: setxkbmap -option

Using xmodmap will only change the key binding while in X. If you need it on the console it’s a little different. The changes below will modify X as well as the console, so I always do it this way.

For Linux add this to /etc/rc.local (or make an init script):

(echo $(dumpkeys |grep -i keymaps); echo keycode 58 = Control) | loadkeys - 

For Solaris on a PC with a USB keyboard edit /usr/share/lib/keytables/type_6/reset (for other types of keyboards you would replace type_6 with the appropriate type):

key 57 all shiftkeys+capslock 
key 57 all shiftkeys+leftctrl up shiftkeys+leftctrl 

Naturally you can replace Control with any key you would like.

Источник

How to toggle off Caps Lock by Shift key?

I get used to turn Caps Lock off by Shift in Windows. That way I never need to check whether Caps Lock is on when I just want to type a first letter in uppercase. But how can I do the same in Ubuntu? iF sHIFT CANCELS cAPS lOCK YOU RARELY NEED TO FIX YOUR TEXT TYPED IN WRONG CASE.

Читайте также:  Linux определить тип памяти

Even though your question applies to Ubuntu 14.04 and answer was about 20.04 as you last were seen 14 minutes ago, kindly accept it. BTW 55 points in 5 years is close to a record.

I agree to accept an answer. But first I want to make sure it works! The problem is I don’t have that system installed any more, so I am now installing gnome on my father’s computer 🙂

4 Answers 4

First install gnome-tweak-tool by using this command:

$ sudo apt-get install gnome-tweak-tool 

Now open ‘Tweaks’ application, then go to : Keyboard & Mouse → Keyboard → Additional Layout Options → Miscellaneous compatibility options → check ‘Shift cancels Caps Lock‘. Close window.

Works fine in Ubuntu 20.04.

Update for Ubuntu 22.04:

First install gnome-tweaks by using this command (thanks @Paul P)

$ apt-get install gnome-tweaks 

Then open «Tweaks», find option within Keyboard & Mouse → Keyboard → Additional Layout Options → Compatibility options → and check ‘Shift cancels Caps Lock‘.

This is in the advanced keyboard options. I don’t think one need to install anything additional to get these options.

User @walter-monroe suggested change with argument «Shift cancels Caps Lock» in Gnome Tweaks only works when Shift is pressed and released. The intended solution is for Shift to be pressed in combination with another key when starting a new sentence. which I agree, but his proposed option «Both Shift together enable Caps Lock; one Shift key disables it.» do not meet that behaviour (I tested within Ubuntu 20.04.5). It think there not exist such an option currently.

I have also been searching for the same functionality. It’s easy to use, you never have to delete those uppercase characters when you don’t need them. Just by pressing Shift to start the sentence with an uppercase character, you «automatically» deactivate CapsLock.

Here are the instructions for Linux Mint:

Go to System Settings > Keyboard.

Next, choose your keyboard layout, then click Options.

Under «Miscellaneous compatibility options», check the box next to «Both Shift keys together activate Caps Lock, one Shift key deactivates».

I have no Ubuntu available to test, but hopefully the instructions are equally valid.

Источник

Оцените статью
Adblock
detector