# Getting my laptop's "Fn" keys to work

## bsander

How can I include my laptop's Fn Keys in shortcuts under KDE? When I press the key it doesn't get recognised, only some keycombos for adjusting screen brightness and switching to an external screen work (which I think are hardware-powered).

----------

## inode77

What laptop do you have?

For ibm there's "ibm-acpi" to get the FN do something usefull (via ACPI events).

For other brands there are other tools if you're lucky.

----------

## bsander

 *inode77 wrote:*   

> What laptop do you have?
> 
> For ibm there's "ibm-acpi" to get the FN do something usefull (via ACPI events).
> 
> For other brands there are other tools if you're lucky.

 Okay, I read up on that acpi stuff and I'm now so far that I get all sorts of codes when reading /proc/acpi/event . But how do I bind those "events" to keys I can use as KDE shortcuts (for instance controlling JuK with my cd buttons)?

-edit- It's an ASUS M2400 by the way. I have acpi4asus.

----------

## bsander

I haven't found an answer for this yet, so I'm going to try again. Is there anybody here that knows how I could do this?

----------

## inode77

You emerge acpid (normaly already installed => "rc-update add acpid default" => /etc/init.d/acpid start)

Edit "/etc/acpid/default.sh" as you like:

```
#!/bin/sh

# Default acpi script that takes an entry for all actions

set $*

group=${1/\/*/}

action=${1/*\//}

case "$group" in

        button)

                case "$action" in

                        power)

                                logger "[ACPI] power button pushed"

                                reboot

                        ;;

                        *)

                                logger "[ACPI] action $action is not defined"

                        ;;

                esac

        ;;

        ibm)

                case "$action" in

                        hotkey)

                                case "$4" in

                                        # Fn+F3

                                        00001003)

                                                state=$(/usr/bin/radeontool regs | grep RADEON_LVDS_GEN_CNTL)             

                                                if [[ "$state" = "RADEON_LVDS_GEN_CNTL=003dffa1" ]] ; then

                                                        cmd="off"

                                                else

                                                        cmd="on"

                                                fi

                                                /usr/bin/radeontool light "$cmd"

                                                logger "[ACPI] lcd backlight $cmd"

                                        ;;

                                        # Fn+F4

                                        00001004)

                                                logger "[ACPI] FN+F4 not implemented yet"

                                        ;;

                                        # Fn+F5

                                        00001005)

                                                state=$(cat /proc/acpi/ibm/bluetooth | awk '/enabled/ { print $2 }')

                                                if [[ $state == "no" ]] ; then

                                                        cmd="enable"

                                                else

                                                        cmd="disable"

                                                fi

                                                echo "$cmd" > /proc/acpi/ibm/bluetooth

                                                logger "[ACPI] $cmd bluetooth"

                                        ;;

                                        # Fn+F7

                                        00001007)

                                                logger "[ACPI] FN+F7 not implemented yet"

                                        ;;

                                        # Fn+F9

                                        00001009)

                                                 state=$(/sbin/ifconfig ath0| awk '/ath0/ { print $5 }')

                                                 if [[ $state == "11:22:33:44:55:66" ]] ; then

                                                        /etc/init.d/wlan_uni stop

                                                 else

                                                        /etc/init.d/wlan_uni start

                                                 fi

                                        ;;

                                        # Fn+F12

                                        00001012)

                                                /etc/init.d/xdm restart

                                        ;;

                                        # Hotkey Event default

                                        *)

                                                logger "[ACPI] ibm/hotkey HKEY $4 pushed but not defined"

                                        ;;

                                esac

                        ;;

                        *)

                                logger "[ACPI] No matching hotkey id found"

                        ;;

                esac

        ;;

        *)

                logger "[ACPI] $*"

        ;;

esac

```

Add this (the way you like) to your "/etc/conf.d/local.start":

```
# Configure the ibm-acpi module to get the hotkey events

echo "0x0150" >| /proc/acpi/ibm/hotkey

echo "enable" >| /proc/acpi/ibm/hotkey

```

----------

## bsander

Thanks, that's really helpful. The only thing I miss (maybe you know) is if there's a way to bind those keys to KDE in-program shortcuts (KDE should be able to recognise the key press combination). Is that possible?

----------

## inode77

Sorry not using KDE => no idea.

I don't think it's possible if the start xev and use the fn keys and they don't generate x11 keypress events. I don't know about possabilities to generate them by script or similar.

----------

## Archangel1

You're looking for Control Centre > Regional and Accessibility > KHotKeys

That should work okay for binding volume keys etc; mine generate key events like "XF86AudioRaiseVolume", which I've bound to "amixer set Master 5+". I imagine you could use it to make KDE do something directly (as a DCOP call I guess) but I don't know how  :Smile: 

If it doesn't pick up key events, have a play about in Keyboard Layout; if that's not set to a keyboard with the extra buttons it won't pick them up.

This won't work for suspend buttons; they generate ACPI events rather than keyboard ones. In that case inode77 seems to know what he's talking about, so have a play with that ACPI script.

----------

## Dgege

I suggest you try a wonderful program called lineak. Google it and you'll find it (I think it's in portage too).

It does exactly what you need.

Georges.

----------

## bsander

Sounds great, I'll try it over the weekend  :Smile: . Thanks!

----------

