GithubHelp home page GithubHelp logo

adam-savard / keyboard-function-keys-linux Goto Github PK

View Code? Open in Web Editor NEW
339.0 6.0 76.0 35 KB

A small script to allow various keyboards to boot up with function keys enabled by default.

License: MIT License

function keyboard-layout keys

keyboard-function-keys-linux's Introduction

Enable Function Keys On Keychron/Various Mechanical Keyboards Under Linux, with systemd

Below, you'll find the steps required to create a systemd command that will run at boot to disable the media keys and restore f1-f12 functionality. Note that these steps have been tested with Keychron keyboards in Windows Mode, not Mac Mode.

Step 1

Open a terminal window and enter the following command:

# Set the EDITOR variable with EDITOR=nano, uncommenting the line directly below
# EDITOR=nano
sudoedit /etc/systemd/system/keychron.service

Step 2

Paste the following into the window:

[Unit]
Description=Disable media keys and substitute in function keys

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/bin/bash -c "echo 0 > /sys/module/hid_apple/parameters/fnmode"
ExecStop=/bin/bash -c "echo 1 > /sys/module/hid_apple/parameters/fnmode"

[Install]
WantedBy=multi-user.target

Press ctrl+o and then ctrl+x to exit.

Step 3

In the terminal, type the following:

systemctl enable keychron

Step 4

That's it! A reboot, and you'll see that the function keys have been re-enabled. Alternatively, run this command to see the changes right away: systemctl start keychron

Contributing

If you confirm that your keyboard works with this script as expected, create a ticket and I'll add it to the list of user-tested keyboards. Alternatively, submit a PR with a modification to this readme.

User Tested Keyboards

Closing Remarks

If you want to simply drag/drop the file that you create manually in the steps provided, I have it under the scripts folder in this repo. Download it and drop it in /etc/systemd/system/, doing Step 3 at the end.

keyboard-function-keys-linux's People

Contributors

adam-savard avatar lesandie avatar mathetes87 avatar thekenu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

keyboard-function-keys-linux's Issues

Work around for C1 on Manjaro

Instead of:
ExecStart=/bin/bash -c "echo 0 > /sys/module/hid_apple/parameters/fnmode"

I have used:
ExecStart=/bin/bash -c "echo 'options hid_apple fnmode=0' | sudo tee /etc/modprobe.d/hid_apple."

no need for service, same can be accomplished with grub2-mkconfig

Fedora

modinfo hid_apple | egrep "^parm" # view available parameters
echo "options hid_apple fnmode=2 swap_opt_cmd=1" > /etc/modprobe.d/hid_apple.conf
sudo modprobe -r hid_apple ; sudo modprobe -v hid_apple
cat /sys/module/hid_apple/parameters/{fnmode,swap_opt_cmd} 
sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg

after reboot verify status with cat /sys/module/hid_apple/parameters/{fnmode,swap_opt_cmd}

Ubuntu

Apply parameters using sudo update-initramfs -u

This script is only tested and validated on the K2

This is more of a notification to anyone that comes across the repo with another keyboard model from Keychron, like the K1. Unless someone can chime in that this fixes all issues with all their keyboards then I wouldn't assume this script works.

That said, it won't actually hurt anything if you give the actual line of bash a try in the terminal. It would be reset on reboot.

Context: Windows and/or Mac

Does this depend on the keyboard being in Mac mode (the switch at the back/at the left)? If so, perhaps mention that on the page?

Or even mention it in any case, whether the switch at the back/at the left is supposed to be in a particular position or not.


(I discovered the page through a Reddit comment.)

(I am on Linux 100% and am willing to test stuff, but that is with Keychron V and Keychron K Pro series full-sized keyboards (QMK-based only), so it probably doesn't apply. I have about seven months experience with Keychron keyboards (incl. implementing a custom macro execution engine to allow cancelling macros in progress), but I repurposed an old Apple AEKII some years ago to use QMK (based on AVR / Arduino Micro).)

Didn't work on boot.

Hi,

I recently bought a Keychron K1 V4 and found your guide on how to restore the function keys. I know you said it's for K2 but I figured it should work for any other Keychron keyboards like mine and any other apple keyboards in general. It's great and it works when I type systemctl start keychron manually. However, it couldn't be automatically start on boot. Here is the error message I copied from journalctl.

Nov 28 13:21:01 Arch-AMD systemd[1]: Starting The command to make the Keychron K2 work...
Nov 28 13:21:01 Arch-AMD bash[504]: /bin/bash: /sys/module/hid_apple/parameters/fnmode: No such file or directory
Nov 28 13:21:01 Arch-AMD systemd[1]: keychron.service: Main process exited, code=exited, status=1/FAILURE
Nov 28 13:21:01 Arch-AMD systemd[1]: keychron.service: Failed with result 'exit-code'.
Nov 28 13:21:01 Arch-AMD systemd[1]: Failed to start The command to make the Keychron K2 work.

I am still a newbie in Linux so I am not sure what is the correct way to fix this. I found some other guides online which work well with apple keyboards, and it seems to me it's a simpler way. Here is way worked for me:
I created a file /etc/modprobe.d/hid_apple.conf and here is the content inside:

# /etc/modprobe.d/hid_apple.conf
option hid_apple fnmode=0

systemd watchdog0 timeout - solution

Hey,

i had problem with the fact that sometimes the watchdog0 from systemd cant properly kill the service (obviously bc of the oneshot nature of the script).

I personally fixed that with an extra RemainAfterExit=yes right before/after the exec Type (oneshot).
You still get the "keychron2 service cant stop blablabla" but for me that worked, the system now shuts down properly and quickly.

Not sure if someone had this issue as well with their K2 and System Combi but maybe that helps someone.

so long

Keychron K3E1 confirmed working with Linux

I tested with Kali on a Raspberry Pi 4. turning on and of through reboots keeps the F-keys working as expected. Turning F5 & F6 on and of with Fn + K + C (4 sec) also works.

Hope this helps.

//Serge

Does not work in fedora

I am running fedora 35. I have followed the specified procedure. The created systemd service (keychron.service), runs correctly when the keyboard is plugged in on startup. It appears however that if the system has already booted and then the keyboard is connected via Bluetooth then the service does not run i.e. change fnmode to 0. How can i ensure that the service runs every time the keyboard is connected?

Keychron K1

Can I use the same script for keychron k1?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.