You are not logged in.
So, I recently bought an A4Tech XL-747H gaming mouse, which has internal memory for macros/key bindings. In Windows, to switch between two available profiles, one presses scroll lock on the keyboard. In Linux, this behaviour appears to be less defined.
First, I attempted
xset led 3
which turned on the Scroll Lock led, and switched the mouse profile. Perfect, but requires typing the command each time (or putting it in a script) to switch modes.
Next, I tried
xmodmap -e 'add mod3 = Scroll_Lock'
which makes the scroll lock button turn the led on and off, but not switch the mouse profile. It doesn't actually appear to affect anything apart from the LED... Interestingly, when the LED is on from the xset command, the Scroll Lock key no longer toggles it.
So, my question is, how can I get the behaviour from xset mapped to the Scroll_Lock key? I would also like a better understanding of what it is my mouse is responding to. xset seems to be setting more than just the LED.
Last edited by dewert (2012-02-21 04:56:14)
Offline
Try xbindkeys (and xev to find out what your key actually does).
Offline
Ok, thanks for recommending xbindkeys. I've already found out what keycode it produces, but there is no apparent way to *toggle* the led in the way my mouse wants. I'm still looking, of course, but if anyone knows, that'd be great.
Output is the same both when the led is on and when it is off:
$ xbindkeys --key
Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"(Scheme function)"
m:0x30 + c:78
Mod2+Mod3 + Scroll_Lock
However, this is not the case in xev:
Turning LED on
KeyPress event, serial 41, synthetic NO, window 0x3c00001,
root 0x15d, subw 0x0, time 4163571, (-456,241), root:(252,579),
state 0x10, keycode 78 (keysym 0xff14, Scroll_Lock), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
Turning LED off:
KeyPress event, serial 41, synthetic NO, window 0x3c00001,
root 0x15d, subw 0x0, time 4163747, (-456,241), root:(252,579),
state 0x30, keycode 78 (keysym 0xff14, Scroll_Lock), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
The state switches between 0x10 and 0x30, and I don't know how to get xbindkeys to respond to this.
Offline
Ok, I figured it out. For posterity, what I did was as follows:
- wrote a bash script, saved it in my home directory:
#!/bin/bash
MASK=`xset q | grep LED | cut -d' ' -f 21 | cut -b 8`
if [ $(($MASK & 4)) = 4 ]; then
xset -led 3
else
xset led 3
fi
-added the following to ~/.xbindkeysrc:
"/home/<username>/scripts/toggle-led.sh"
Scroll_Lock
-added xbindkeys to my xinitrc
Done!
Offline
@dewert: Thank you very much for posting solutions here. I bought a new keyboard with LED backlight. I'm using RHEL 6 and with your solution I'm able to turn on/off keyboard backlight using scroll lock.
Regarding you bash script, I'm just curious to know why you used "bitwise AND" for comparison and not any other arithmetic operators. I would really appreciate if you could explain it.
Offline
@sameer741 This can be reduced/simplified to:
MASK=$(xset q | awk '/LED/{print substr($NF,8,1)}')
if [ $(($MASK & 4)) = 4 ]; then
xset -led 3
else
xset led 3
fi
# or simply this one line will do also
if [ $(($(xset q | awk '/LED/{print substr($NF,8,1)}') & 4)) = 4 ];
then xset -led 3; else xset led 3; fi
This could be reduced further to use a variable before 'led', although the benefit is questionable. Xset uses hexadecimal values, so the last character awk gets can be a letter. Write the numbers out in binary, then you should recognize why binary operator is used. Note that there can be values above 4, without the 3rd bit set, which xset uses for led 3. Turn other leds like the numlock on, and run 'xset q | awk..', to see how the value changes. It is not waterproof however, turn the led 4 on (value 8), and the above will not work when trying to revert (value c), but this should:
if [ $(($(echo 'ibase=16;obase=A;'$(xset q | awk '/LED/{print toupper(substr($NF,8,1))}') | bc) & 4)) = 4 ];
then xset -led 3; else xset led 3; fi
Offline