How to turn on/off leds by terminal?

10

3

I would like turn on/turn off some of my leds running a command on linux.

I use Ubuntu 12.04 LTS.

I tried

xset led named "Scroll Lock"
xset led named "Num Lock"
xset led 2             (this is the number of Scroll Lock as `xset q` says)
xset led 1

but nothing works.

Tried

setleds +num
setleds +scroll

but I got a error message saying Error reading the current settings of flags. Maybe you're not on the console? (I was in a terminal).

So, how can I perform this?

GarouDan

Posted 2012-06-16T00:32:42.613

Reputation: 477

Answers

9

xdotool key Num_Lock

Is the an answer (the easiest you're likely to find); inverting the state, it also provides a path to search (xinput and modifying a slave keyboard state) if you really just want to set an led status.

I too ran across my Num Lock keyboard LED and X11 state differing recently (happens with remote desktops, games, etc)

This reference explains what's going on, and almost has the complete solution (but it has a case-typo, you need Num_Lock not Num_lock).

http://blog.ssokolow.com/archives/2013/04/18/how-to-invert-your-x11-numlock-led/

Michael J. Evans

Posted 2012-06-16T00:32:42.613

Reputation: 191

Note that xdotool key Num_Lock is not as innocent as turning a LED on or off; It is the equivalent of actually pressing the key! – Serge Stroobandt – 2018-11-04T12:14:46.403

This should be the accepted answer. Best solution I've ever seen. Thank you! The lights are so annoying! – jocap – 2014-05-13T21:22:20.480

5

To turn Scroll Lock led on run:

xset -led 2 led on

To turn it off run:

xset -led 2 led off

Aleksey Alekseev

Posted 2012-06-16T00:32:42.613

Reputation: 51

1

Press Ctrl+Alt+F1, login, and then try setleds.

VenkatH

Posted 2012-06-16T00:32:42.613

Reputation: 606

Interesting. setleds (not xset) worked for me now too. Looks like we need set a display. I tried several things but nothing worked. But, looks we're almost. – GarouDan – 2012-06-17T11:28:54.727

2This isnt the final answer to me, because I need this working on the gui display, not at the console display. – GarouDan – 2012-07-23T19:55:39.933

0

As noted in this answer, if your screen is on TTY1, but you try to control the LEDs from somewhere else (such as an SSH session), you can use setleds in the following way:

setleds -L +num +caps +scroll < /dev/tty1

cdauth

Posted 2012-06-16T00:32:42.613

Reputation: 323

0

Install xf86-input-keyboard if you don't have it.

Set kbd_mode -u

Make sure you don't have multiple instances of the KB (check what XINPUT: reports).

Overmind

Posted 2012-06-16T00:32:42.613

Reputation: 8 562

-1

Just use the command:

numlockx on 

or

numlockx off

to change the state.

minux

Posted 2012-06-16T00:32:42.613

Reputation: 1

4This is rather brief: some more detail would be helpful. For example, in what circumstances does this command work? – David Richerby – 2015-04-30T10:33:06.807

It does exactly what it sounds like. – Jon – 2015-04-30T20:08:00.817