当前位置: 首页>>技术教程>>正文


kernel – Fn 键如何工作?

, ,

问题描述

我想知道 Fn 键在我的笔记本电脑中是如何工作的。我认为存在一个内核模块,它可以捕获 Fn 键并调用一些脚本来做某事。在我的笔记本电脑中,Fn + F2 切换无线和 blue-tooth 的电源。

这是 acpi_listen 的输出,当我按下 Fn + F2

hotkey ATKD 0000005d 00000019
hotkey ATKD 0000007e 00000009

并且,以下是 xev 对于 Fn + F2 的输出

keycode 238 press
keycode 238 release
keycode 237 press
keycode 237 release

我想每当我按下 Fn + F2 两个事件都会跳出。我试图找出为这些键执行了哪些操作。任何想法表示赞赏;)

最佳思路

Synetech 对 Fnhere 给出了非常易读的解释

Technical Details

When you press a key on a keyboard, the keyboard controller (a small IC chip inside the keyboard) detects the electrical circuit and processes it to decode which key was pressed and then sends the scancode to the motherboard. The operating system receives scancode from the BIOS and then performs whatever action it needs to in order to process that keypress.

With most keys, this is simple enough. If you press the A key, its keyboard controller sends the scancode to the motherboard which then passes it to the OS which in turn usually prints ‘A’. (If the OS detects that one of the modifier keys is currently held down, then it may do something different. In fact, you can configure it to do whatever you want when the A key is pressed with or without modifiers.)

Now the Fn key is special. When you press it by itself, nothing happens because it is exclusively a modifier key and is not (generally) meant to do anything on its own. When you hold it and press another key, the keyboard controller detects that and looks in its built-in table to see if it is a known combination. If the combo is not in the table, then it just ignores it, but if the combo is in the table, then it looks up the associated scancode and sends that.

What does the OS end up seeing? It does not see the scancode for the Fn key and the scancode for the other key. Instead, it sees a single scancode associated with whatever function the Fn-combo has been set to. For example, if the laptop manufacturer has set the Fn+Down Arrow combo to reduce the volume, then the OS sees the scancode associated with the Volume Down, which some keyboards actually have.

另请注意,Fn 键可在操作系统中使用 independently

此外,this article 可能会帮助您指明正确的方向:

The kernel has its own scancode to keycode mapping table, so it maps a certain scancode to a keycode. You can look into /usr/include/linux/input.h to see what your kernel uses for scancode to keycode mapping – it is called a keymap.


后记

我可能需要在一定程度上反驳早先的说法,即 Fn 键完全独立于操作系统工作;在这里不讨论更多技术细节,结果似乎是您的操作系统可能不会 “support” 全部或部分键盘的 Fn 键,例如:

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/12249.html,未经允许,请勿转载。