Search This Blog

Friday, October 6, 2023

Keyboard: Remapping function keys

Looking at my keyboard I was wondering if there was a way for me to change the built in functions of the keyboard such as "open default mail app" or "play/pause music".

Seems like there is a way by editing the registry.

The following way will change the settings for all users of the computer, and as always, the registry is a dangerous place to edit if you aren't careful.

1. Open regedit as administrator and go to the following adress:  HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\

2. You will see numbered folders (called "keys"). Folder number 16 is your media player, in my case it was preset to open Windows Media Player. Thus a good candidate to be replaced.

3. Within the folder of your choice create a string value (REG_SZ) called ShellExecute.
Open that file up and set its value to a path leading to your program, put within quotation marks.
In my case I chose the path to PowerShell: "C:\Program Files\PowerShell\7\pwsh.exe"


In my case the effect was immediate, no restart was required. However, the day after it was not working as intended. It seemed to be working only if I had an admin session of regedit open. Trying to add it to Current User hive did not seem to work either.

We know that folder number 16 equated to the media button. What other buttons might there be?
Well this article lists all the potential numbers, obviously your keyboard might not have the email button and you might not be able to remap the email button to another program. I only chose to inspect/modify the already existing registry keys (15, 16, 17, 18, 7) instead of creating new ones.

Based of the article we can see the following examples of registry keys and their inherent functions:

1 = Browser navigation backward, 2 = forward, 3 = refresh, 4 = stop, 5 = search, 6 = favorites, 7 = home.

8 = mute volume, 9 = volume down, 10 = volume up, 11 = next track, 12 = previous track, 13 = stop, 14 = play/pause

15 = mail, 16 = media, 17 = app 1, 18 = app 2, 19 = bass down, 20 = bass boost, 21 = bass up, 22 = treble down, 23 = treble up

The numbers are arbitrary, you have to look where the functions are located physically on your keyboard. In my case the number 16 (media) was located on fn + escape. Thus, when I pressed fn + escape it started my PowerShell window. Beware, it seems to be unstable and might stop working for you though.

Here is the reg file content that you can work with, as you can see I experimented with Current User.

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\AppKey\16]
"ShellExecute"="C:\\Program Files\\PowerShell\\7\\pwsh.exe"

Enjoy!