Generic way to remap every media button

Generic way to remap every media button

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

答案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

答案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

相关内容