adam-savard / keyboard-function-keys-linux Goto Github PK
View Code? Open in Web Editor NEWA small script to allow various keyboards to boot up with function keys enabled by default.
License: MIT License
A small script to allow various keyboards to boot up with function keys enabled by default.
License: MIT License
Just confirming this also works on my Ninja87BT.
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
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."
I tested it just now, it works perfectly
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?
Just confirming that it also works on the Keychron C1 keyboard. Thank you for sharing this script!
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}
Apply parameters using sudo update-initramfs -u
I didn't do a full reboot of the machine, only
sudo systemctl start keychron
Maybe it is worth it to add it to the README in the STEP 4, as an alternative.
Can I use the same script for keychron k1?
Confirming: it also works with Flesports MK870.
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).)
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
Requirement:
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
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.
Just to validate this it does in fact work on my keychron c2
Just tested this out after being unable to use the function keys by default on my Keebmonkey 1800/James Donkey RS2 (same keybaord, different branding). Thank you for the help!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.