Generic way to remap every media button

24,560

Solution 1

This is a generic way to remap any keyboard buttons. Even weird ones


  1. Use KeyCodes (portable,415 KB) to catch the key code. Download, extract and start KeyCodes3.exe. Press your mysterious button and you'll see the key code as decimal number

    enter image description here

    An alternative way was this AHK script which uses a keyboard hook and "KeyHistory"

    #Persistent
    #InstallMouseHook
    #InstallKeybdHook
    while !(getKeyState("F1", "T"))
          KeyHistory
    return
    esc::exitapp
    

    enter image description here

  2. Convert the number from decimal to hexadecimal: 171 » AB

  3. Use the portable version of AutoHotKey to remap the button.
    Download and extract the .zip version of your choice somewhere. No installation needed.
    Create a new text file and paste

    #NoEnv, #Persistent, #SingleInstance
    vkB5::return                ;music node button  181 » B5   do nothing
    vkAC::return                ;home button        172 » AC   do nothing
    vkAA::return                ;search button      170 » AA   do nothing
    vkAB::Run, c:\myapp.exe     ;star button        171 » AB   execute tool
    vkB4::Send {Volume_Mute}    ;mail button        180 » B4   mute/unmute
    
    • vk stands for virtual key code followed by your hexadezimal key code you want to remap
    • :: is the remap operator. Left is the trigger, right of it is your new button or action
    • Send {<my_new_key>} could be any key from this list.
      Alternatively you could execute a custom path with the Run command.
      Or if you want to to execute a media button again, use {vkAB} as action
  4. Create a new shortcut in your autostart folder to start your AHK script on each boot. For example

    "D:\Tools\AutoHotKey\AutoHotkey.exe" "D:\Tools\AutoHotKey\RemapKeys.ahk"
    

After a reboot or manual AHK script start, all buttons are remapped

Solution 2

In short: you can find multimedia keys mapping in the following registry key: "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey"

E.g. the mail key usually launches the default mail app.

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\15\RegisteredApp = "Mail"

If you want to replace this to open Notepad,

HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\15\ShellExecute = "notepad.exe"

(Or change HKLM if you want to modify for all users etc)

RegisteredApp means the app registered for that function will be called. (Like Mail above)

Association Means the app associated with a particular file type will be opened. For e.g. the Media key is registered by default to .cda, meaning the default app used for playing music CDs will be opened on pressing that key.

ShellExecute opens a particular program to be run.

For more details read this article

Share:
24,560

Related videos on Youtube

nixda
Author by

nixda

Updated on September 18, 2022

Comments

  • nixda
    nixda over 1 year

    Today I tried to remap some keyboard media keys to more useful functions and failed to do so.

    enter image description here

    The problem

    • The manufacturer doesn't provide a utility to bind and execute custom commands.
      My previous keyboard from Logitech had such options in their SetPoint software
    • The key codes (or scancode) were not recognized by most programs which I used to catch the underlying key codes.

      For example the otherwise excellent tool SharpKeys has a catch mode where it tells you what key you've just pressed. It took me some time to realize that it told me a wrong key code During my tests I pressed the "star button" in the top right and SharpKeys tells me that this is the key "D" with it's key code 00_20. But the correct key code would be 00_181

      Another try was this AutoHotKey script which also failed to recognize my unusual media keys

    The task

    • Find the correct key codes even for unusual media buttons
    • Remap all media keys without any installation of an additional tool or program. A registry tweak, the use of an already installed driver or a small portable app is acceptable
  • DavidPostill
    DavidPostill almost 8 years
    Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
  • BornToCode
    BornToCode over 7 years
    Everything worked except mapping a mute key to run a command (e.g. vkAD::Run, c:\myapp.exe didn't work for me), I had to remap it twice to make it work, something like vkAD::F21 and then another mapping: F21::Run, c:\myapp.exe
  • PhilMacKay
    PhilMacKay about 7 years
    My antivirus (ESET EndpointAntivirus) flagged the executable download as a threat.
  • PhilMacKay
    PhilMacKay about 7 years
    I have been able to remap "Calculator" but not "Media PLay/Pause".
  • Joel Coehoorn
    Joel Coehoorn almost 4 years
    Looks like the KeyCodes download is dead :(
  • nixda
    nixda almost 4 years
    @JoelCoehoorn yeah, looks like. But the source code is still available. Maybe someone can build an executable? I have no idea what programming language was used there
  • Blue Raspberry
    Blue Raspberry over 3 years
    For Step 1's alternative approach to get the codes using AutoHotKey, the instructions at the first answer here have some additional details which may be useful for newer users.
  • ben_wing
    ben_wing over 2 years
    @JoelCoehoorn, KeyCodes pre-compiled application was saved by the WayBack Machine at web.archive.org/web/20170708203744/http://delphiforfun.org/…