Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on Auto-enable FN-toggling for the first N FN keys

Parent

Auto-enable FN-toggling for the first N FN keys

+4
−0

How can I auto-enable FN-toggling for the first N FN keys? F7-F12 on my keyboard are used for audio control, while, many games that I play, use the lower FN keys. Therefore, I'd like to relieve myself of the need to hold down the FN key for F1-F6. In other words, I'd like to change the default FN key state for those keys only.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Wayland (1 comment)
Post
+2
−0

It is true that Fn combinations are usually implemented in hardware, but in X11 (not Wayland of course!) you can circumvent this issue for most or all your keys.[1]

For example, my F3 -> F3 and my Fn+F3 -> {Switch monitor}.

Find out the keycodes of the keys

In a terminal, launch xev. Press Fn+F3 and see the output in the terminal:

KeyRelease event, serial 32, synthetic NO, window 0x1400001,
    root 0x25a, subw 0x0, time 11205128, (-592,394), root:(2,689),
    state 0x0, keycode 235 (keysym 0x1008ff59, XF86Display), same_screen YES,

So the keycode for Fn+F3 is 235. Repeat the steps for F3 to determine that the keycode for F3 is 69.

Dump your XKB map to a file

xkbcomp "$DISPLAY" xkb

Swap the keycodes in the map

Open the created xkb file in your text editor.

In the xkb_keycodes section of the file, swap the keycode 69 <-> 235. I.e., if the section looks like this initially,

    <FK01> = 67;
    <FK02> = 68;
    <FK03> = 69;
    [...]
    <I235> = 235;
    <I236> = 236;
    <I237> = 237;

it should look like this afterwards:

    <FK01> = 67;
    <FK02> = 68;
    <FK03> = 235;
    [...]
    <I235> = 69;
    <I236> = 236;
    <I237> = 237;

Load your new XKB map

xkbcomp xkb "$DISPLAY"

Now F3 -> {Switch monitor} and Fn+F3 -> F3.

Further reading


  1. This won't work for combinations that also work directly via hardware, for example, in my computer Fn+F2 will turn the screen on or off. If xev doesn't detect the combination, you are out of luck — unless it is detected by acpi_listen and you can contrive something... food for thought, I really did not try. ↩︎

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Trace of user change (6 comments)
Trace of user change

How much trace of a user change does this leave? In case I ever forget that I did this, can I then figure out I’m responsible for these changes without really giving it much though that it’s possible I did it? How easy is it to revert it, for instance when I replace the keyboard?

Quasímodo‭ wrote 6 months ago

This does not leave a trace, no GUI "settings program" will ever reflect such a change and even setxkbmap -print will look the same. The change does not persist across Xorg sessions (and thus reboots, log-ins) though. It's easy to revert it without killing Xorg, just keep the old and new maps in separate files, so you can always apply it with xkbcomp xkb-new "$DISPLAY" and revert it with xkbcomp xkb-old "$DISPLAY".

So that means I actually have to write an application myself. I can't rely on having to manually set up my desktop experience every time I log on.

Quasímodo‭ wrote 6 months ago

That is a non-issue.

So that means I actually have to write an application myself.

What? How come? You have a file with the desired keymap, you run xkbcomp on it.

I can't rely on having to manually set up my desktop experience every time I log on.

There is a multitude of ways to make a command run on every log in. The operating system wouldn't be used anywhere if it did not support such an elementary task.

Well, that is sort of an application.