Hello I was wondering if it is possible to catch the fn key with js.
What i'm trying to achieve is detect the fn + f7 keypress.
Here is my code which is not triggered with the fn key :
document.addEventListener("keydown", onKeyDown, false);
function onKeyDown(e) {
console.log(e);
}
Update : I found that detecting fn + f5 works on windows but not for my linux. Is there a package to install to add media keys for firefox?
The Fn key is located in the bottom row near the Ctrl key. The exact location of the key may vary depending on the manufacturer and model of the keyboard. The Fn key is located in the bottom row of a keyboard, generally next to the Ctrl key.
Detecting keys in JavaScriptdocument. onkeydown = function (e) { console. log('key down'); console. log(e); };
Make Sure the Fn Keys Are Not Locked On your keyboard, look for an Fn, F lock, or F Mode key. Depending on your laptop, you should press for one time or press and hold for a few seconds. If this didn't work, press the Fn and Esc keys at the same time. Then, try to use one of the Function keys.
We can also detect keypress using the wait() function defined in the keyboard module. The wait() function takes a character as input. Upon execution, it keeps waiting until the user presses the key passed as an input argument to the function. Once the user presses the right key, the function stops its execution.
Most FN keys are implemented in firmware and won't be recognized by applications. You can use a website like this one to test out what javascript can handle:
http://keycode.info/
You can't catch when fn
key was pressed.
However if you press fn+F7
it would generate different event
object than if you press solely F7
- considering that there is function bound to that key. So in my case I do not have anything bound on F7, therefore there will be no event generated if I press fn+F7
keys.
If I press F3
and then fn+F3
, following codes will be generated:
KeyboardEvent {isTrusted: true, key: "F3", code: "F3", location: 0, ctrlKey: false, …}
KeyboardEvent {isTrusted: true, key: "AudioVolumeUp", code: "AudioVolumeUp", location: 0, ctrlKey: false, …}
Hope this helps.
----More info below----
As I expected fn
key does not really generate any keycode. Instead, on the hardware level, when pressed in combination with some other keys it is generating unique keycode.
Information based on answer from this question: https://askubuntu.com/questions/827925/remapping-the-fn-key
And this: https://askubuntu.com/questions/270416/how-do-fn-keys-work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With