Difference between revisions of "Activating Numlock on Bootup"

From ArchWiki
Jump to: navigation, search
m (remove from Desktop environments category)
m (The previous service did not work and produced errors. I made changes to allow the service to start and make it similar to the wiki on Accessibility here: https://wiki.archlinux.org/index.php/Accessibility#Sticky_Keys to maintain consistency.)
 
(23 intermediate revisions by 18 users not shown)
Line 4: Line 4:
 
[[es:Activating Numlock on Bootup]]
 
[[es:Activating Numlock on Bootup]]
 
[[it:Activating Numlock on Bootup]]
 
[[it:Activating Numlock on Bootup]]
[[ja:Activating Numlock on Bootup]]
+
[[ja:起動時に Numlock を有効化]]
 
[[ru:Activating Numlock on Bootup]]
 
[[ru:Activating Numlock on Bootup]]
[[tr:Açılışta_numlock_etkinleştirme]]
+
[[tr:Açılışta numlock etkinleştirme]]
 
[[zh-CN:Activating Numlock on Bootup]]
 
[[zh-CN:Activating Numlock on Bootup]]
 
== Console ==
 
== Console ==
Line 12: Line 12:
 
=== Using a separate service ===
 
=== Using a separate service ===
  
[[Pacman|Install]] the package {{aur|systemd-numlockontty}} from the [[AUR]].
+
* [[Install]] the package {{AUR|systemd-numlockontty}} from the [[AUR]].<br>Then [[enable]] the {{ic|numLockOnTty}} service.
  
Now you should enable the {{ic|numLockOnTty}} daemon. Read [[Daemons]] for more details.
+
* Alternatively, if you do not want to install an aur package to implement this, you can simply create a file in {{ic|/usr/bin}} similar to: {{bc|<nowiki>
 +
#!/bin/bash
  
=== Extending {{ic|getty@.service}} ===
+
#Ybalrid on 01/02/13
 +
#This script set the numpad on for the 6 first tty
 +
 
 +
for tty in /dev/tty{1..6}
 +
do
 +
    /usr/bin/setleds -D +num < "$tty";
 +
done
 +
</nowiki>}} as done in the aforementioned aur package. Remember to give it a name e.g. numlock.
 +
You will then need to create a service file in {{ic|/usr/lib/systemd/system/}} like:{{bc|<nowiki>
 +
[Unit]
 +
Description=numlock
 +
 
 +
[Service]
 +
ExecStart=/usr/bin/numlock
 +
StandardInput=tty
 +
RemainAfterExit=yes
 +
 
 +
[Install]
 +
WantedBy=multi-user.target emergency.target rescue.target</nowiki>}}{{note|The filename should have a {{ic|.service}} suffix, e.g. {{ic|numlock.service}}.}} Do not forget to [[enable]] the service after you create it.
 +
{{bc|<nowiki># systemctl start numlock</nowiki>}}
 +
 
 +
=== Extending getty@.service ===
  
 
This is simpler than using a separate service (especially since systemd-198) and does not hardcode the number of VTs in a script. Create a directory for drop-in configuration files:
 
This is simpler than using a separate service (especially since systemd-198) and does not hardcode the number of VTs in a script. Create a directory for drop-in configuration files:
Line 26: Line 48:
 
{{hc|activate-numlock.conf|<nowiki>
 
{{hc|activate-numlock.conf|<nowiki>
 
[Service]
 
[Service]
ExecStartPost=/bin/sh -c 'setleds +num < /dev/%I'
+
ExecStartPre=/bin/sh -c 'setleds +num < /dev/%I'
 +
</nowiki>}}
 +
 
 +
To disable the num-lock activation hint displaying on the login screen, edit /etc/systemd/system/getty.target.wants/getty@tty1.service. Add the option '--nohints' to the following line:
 +
 
 +
{{hc|getty@tty1.service|<nowiki>
 +
ExecStart=-/sbin/agetty ....
 
</nowiki>}}
 
</nowiki>}}
  
Line 64: Line 92:
 
  NoUpgrade = usr/share/config/kdm/Xsetup
 
  NoUpgrade = usr/share/config/kdm/Xsetup
  
=== KDE4 Users ===
+
=== KDE Plasma Users ===
  
 
Go to System Settings, under the Hardware/Input Devices/Keyboard item you will find an option to select the behavior of NumLock.
 
Go to System Settings, under the Hardware/Input Devices/Keyboard item you will find an option to select the behavior of NumLock.
Line 70: Line 98:
 
==== Alternate Method ====
 
==== Alternate Method ====
  
Alternatively, add the script the {{ic|~/.kde4/Autostart/numlockx}} containing:
+
Alternatively, add the script the {{ic|~/.kde4/Autostart/numlockx.sh}} containing:
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 77: Line 105:
 
And make it executable:
 
And make it executable:
  
  $ chmod +x ~/.kde4/Autostart/numlockx
+
  $ chmod +x ~/.kde4/Autostart/numlockx.sh
  
 
==== Alternate Method 2 ====
 
==== Alternate Method 2 ====
Line 105: Line 133:
 
When not using the GDM login manager, numlockx can be added to GNOME's start-up applications.
 
When not using the GDM login manager, numlockx can be added to GNOME's start-up applications.
  
[[pacman|Install]] {{Pkg|numlockx}} from the [[Official Repositories|official repositories]]. Then, add a start-up command to launch {{ic|numlockx}}.
+
[[Install]] {{Pkg|numlockx}} from the [[official repositories]]. Then, add a start-up command to launch {{ic|numlockx}}.
 
  $ gnome-session-properties
 
  $ gnome-session-properties
  
 
The above command opens the '''Startup Applications Preferences''' applet. Click '''''Add'''''  and enter the following:
 
The above command opens the '''Startup Applications Preferences''' applet. Click '''''Add'''''  and enter the following:
  
{| border="0"
+
{| class="wikitable"
 
| Name:      ||  ''Numlockx''
 
| Name:      ||  ''Numlockx''
 
|-
 
|-
Line 119: Line 147:
  
 
{{note|This is not a system-wide change, repeat these steps for each user wishing to activate NumLock after logging in.}}
 
{{note|This is not a system-wide change, repeat these steps for each user wishing to activate NumLock after logging in.}}
 +
 +
=== Xfce ===
 +
 +
In the file {{ic|~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboards.xml}}, make sure the following values are set to true:
 +
 +
<property name="Numlock" type="bool" value="true"/>
 +
<property name="RestoreNumlock" type="bool" value="true"/>
 +
 +
=== SDDM ===
 +
 +
In the file {{ic|/etc/sddm.conf}}, add the following line under the {{ic|[General]}} section:
 +
 +
[General]
 +
Numlock=on
  
 
=== SLiM ===
 
=== SLiM ===
Line 133: Line 175:
  
 
And then save the file.
 
And then save the file.
 +
 +
=== LightDM ===
 +
See [[LightDM#NumLock on by default]].
 +
 +
=== LXDM ===
 +
 +
In the file {{ic|/etc/lxdm/lxdm.conf}} uncomment the line:
 +
 +
#numlock=0
 +
 +
and change to:
 +
 +
numlock=1

Latest revision as of 03:56, 2 December 2016

Console

Using a separate service

  • Alternatively, if you do not want to install an aur package to implement this, you can simply create a file in /usr/bin similar to:
    #!/bin/bash
    
    #Ybalrid on 01/02/13
    #This script set the numpad on for the 6 first tty
    
    for tty in /dev/tty{1..6}
    do
        /usr/bin/setleds -D +num < "$tty";
    done
    
    as done in the aforementioned aur package. Remember to give it a name e.g. numlock.
You will then need to create a service file in /usr/lib/systemd/system/ like:
[Unit]
Description=numlock

[Service]
ExecStart=/usr/bin/numlock
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target emergency.target rescue.target
Note: The filename should have a .service suffix, e.g. numlock.service.
Do not forget to enable the service after you create it.
# systemctl start numlock

Extending getty@.service

This is simpler than using a separate service (especially since systemd-198) and does not hardcode the number of VTs in a script. Create a directory for drop-in configuration files:

# mkdir /etc/systemd/system/getty@.service.d

Now add the following file in this directory.

activate-numlock.conf
[Service]
ExecStartPre=/bin/sh -c 'setleds +num < /dev/%I'

To disable the num-lock activation hint displaying on the login screen, edit /etc/systemd/system/getty.target.wants/getty@tty1.service. Add the option '--nohints' to the following line:

getty@tty1.service
ExecStart=-/sbin/agetty ....

Bash alternative

Add setleds -D +num to ~/.bash_profile. Note that, unlike the other methods, this will not take effect until after you log in.

X.org

Various methods are available.

startx

Install the numlockx package and add it to the ~/.xinitrc file before exec:

#!/bin/sh
#
# ~/.xinitrc
#
# Executed by startx (run your window manager from here)
#

numlockx &

exec window_manager

KDM

If you use KDM as a login manager, add:

numlockx on

to the /usr/share/config/kdm/Xsetup, or the /opt/kde/share/config/kdm/Xsetup for KDM3.

Note that this file will be overwritten on update without creating a .pacnew file. To prevent this, add the following line to /etc/pacman.conf file (omit the leading slash in the path):

NoUpgrade = usr/share/config/kdm/Xsetup

KDE Plasma Users

Go to System Settings, under the Hardware/Input Devices/Keyboard item you will find an option to select the behavior of NumLock.

Alternate Method

Alternatively, add the script the ~/.kde4/Autostart/numlockx.sh containing:

#!/bin/sh
numlockx on

And make it executable:

$ chmod +x ~/.kde4/Autostart/numlockx.sh

Alternate Method 2

This method enables num lock in KDM login screen (e.g. numeric password)

1) Disable "Themed Greeter" in System Settings -> Login Screen

2) in file /usr/share/config/kdm/kdmrc find section

 [X-*-Greeter]

Right after that line, add this:

 NumLock=On

GDM

First make sure that you have numlockx (from extra) installed then add the following code to /etc/gdm/Init/Default:

if [ -x /usr/bin/numlockx ]; then
      /usr/bin/numlockx on
fi

GNOME

When not using the GDM login manager, numlockx can be added to GNOME's start-up applications.

Install numlockx from the official repositories. Then, add a start-up command to launch numlockx.

$ gnome-session-properties

The above command opens the Startup Applications Preferences applet. Click Add and enter the following:

Name: Numlockx
Command: /usr/bin/numlockx on
Comment: Turns on numlock.
Note: This is not a system-wide change, repeat these steps for each user wishing to activate NumLock after logging in.

Xfce

In the file ~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboards.xml, make sure the following values are set to true:

<property name="Numlock" type="bool" value="true"/>
<property name="RestoreNumlock" type="bool" value="true"/>

SDDM

In the file /etc/sddm.conf, add the following line under the [General] section:

[General]
Numlock=on

SLiM

In the file /etc/slim.conf find the line and uncomment it (remove the #):

#numlock             on

OpenBox

In the file ~/.config/openbox/autostart add the line:

numlockx &

And then save the file.

LightDM

See LightDM#NumLock on by default.

LXDM

In the file /etc/lxdm/lxdm.conf uncomment the line:

#numlock=0

and change to:

numlock=1