Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Fn key with js

Hello I was wondering if it is possible to catch the fn key with js. fn key

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?

like image 927
Ananta Avatar asked Apr 20 '18 16:04

Ananta


People also ask

How do I find my Fn key?

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.

How do you check if a key is being held down Js?

Detecting keys in JavaScriptdocument. onkeydown = function (e) { console. log('key down'); console. log(e); };

How do you check if the Fn key is working?

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.

How do you identify a keypress?

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.


2 Answers

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/

like image 84
leo Avatar answered Sep 29 '22 06:09

leo


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

like image 40
GSazheniuk Avatar answered Sep 29 '22 06:09

GSazheniuk