Skip to content

Instantly share code, notes, and snippets.

@taichunmin
Last active June 25, 2024 19:15
Show Gist options
  • Save taichunmin/3e348fe654f2a8acbcdd to your computer and use it in GitHub Desktop.
Save taichunmin/3e348fe654f2a8acbcdd to your computer and use it in GitHub Desktop.
Windows AppKey

如何修改 Windows 鍵盤對應

現在的 Keyboard 通常會附多媒體鍵,不過預設值打開可能就是討人厭音質又差的 Windows Media Player。 如果我們希望這些鍵可以按下去是開啟我們想要的軟體,此時通常要裝 Driver,問題是有時候會找不到 Driver,那也沒關係,直接改機碼就可以囉,以下是說明:

  1. 先執行 regedit
    • 機碼位於 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\
  2. 在其下加入數字機碼,代表對應的 AppKey 按鍵 (詳見對應表)
    • 例:16 就是 Media 切換功能
    • 要換掉的話可以先將原來的值備份
    • 然後添加一字串值名稱為 ShellExecute
    • 值就填入喜歡的撥放器的路徑就可以了

機碼值的對應表

Action Description
RegisteredApp It's not clear how this is (was?) supposed to work. The example in the docs set the value to "mail" which would supposedly open up the application that is registered to handle mail. However, in Vista and Win7, the value for AppKey 15 is association to "mailto" (a MIME handler). My thinking is that "RegisteredApp" must have been deprecated. Another possibility: The registry key HKLM\Software\Clients seems to provide a means for applications to register themselves as the "default app" for some things. If you want to explore this, that's one direction to go (see this blog for some related information). But since you can use ShellExecute to do most anything you want, it seems unnecessary.
Association The value entry is a file extension or MIME type. For instance, the item that's associated with my dedicated "Internet" button is:
Association REG_SZ http
The system will run whatever program is associated with that file type or MIME type.
ShellExecute The value is any command that you can execute by typing in at a DOS prompt or in the Start / Run input box. You can pass arguments to the program, but be sure to wrap the whole thing in quotes. For instance,
ShellExecute REG_SZ "Notepad.Exe MyToDoList.Txt"

AppKey 對應表

AppCommand values from Winuser.h

1 APPCOMMAND_BROWSER_BACKWARD
2 APPCOMMAND_BROWSER_FORWARD
3 APPCOMMAND_BROWSER_REFRESH
4 APPCOMMAND_BROWSER_STOP
5 APPCOMMAND_BROWSER_SEARCH
6 APPCOMMAND_BROWSER_FAVORITES
7 APPCOMMAND_BROWSER_HOME
8 APPCOMMAND_VOLUME_MUTE
9 APPCOMMAND_VOLUME_DOWN
10 APPCOMMAND_VOLUME_UP
11 APPCOMMAND_MEDIA_NEXTTRACK
12 APPCOMMAND_MEDIA_PREVIOUSTRACK
13 APPCOMMAND_MEDIA_STOP
14 APPCOMMAND_MEDIA_PLAY_PAUSE
15 APPCOMMAND_LAUNCH_MAIL
16 APPCOMMAND_LAUNCH_MEDIA_SELECT
17 APPCOMMAND_LAUNCH_APP1
18 APPCOMMAND_LAUNCH_APP2
19 APPCOMMAND_BASS_DOWN
20 APPCOMMAND_BASS_BOOST
21 APPCOMMAND_BASS_UP
22 APPCOMMAND_TREBLE_DOWN
23 APPCOMMAND_TREBLE_UP
24 APPCOMMAND_MICROPHONE_VOLUME_MUTE
25 APPCOMMAND_MICROPHONE_VOLUME_DOWN
26 APPCOMMAND_MICROPHONE_VOLUME_UP
27 APPCOMMAND_HELP
28 APPCOMMAND_FIND
29 APPCOMMAND_NEW
30 APPCOMMAND_OPEN
31 APPCOMMAND_CLOSE
32 APPCOMMAND_SAVE
33 APPCOMMAND_PRINT
34 APPCOMMAND_UNDO
35 APPCOMMAND_REDO
36 APPCOMMAND_COPY
37 APPCOMMAND_CUT
38 APPCOMMAND_PASTE
39 APPCOMMAND_REPLY_TO_MAIL
40 APPCOMMAND_FORWARD_MAIL
41 APPCOMMAND_SEND_MAIL
42 APPCOMMAND_SPELL_CHECK
43 APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE
44 APPCOMMAND_MIC_ON_OFF_TOGGLE
45 APPCOMMAND_CORRECTION_LIST
46 APPCOMMAND_MEDIA_PLAY
47 APPCOMMAND_MEDIA_PAUSE
48 APPCOMMAND_MEDIA_RECORD
49 APPCOMMAND_MEDIA_FAST_FORWARD
50 APPCOMMAND_MEDIA_REWIND
51 APPCOMMAND_MEDIA_CHANNEL_UP
52 APPCOMMAND_MEDIA_CHANNEL_DOWN
53 APPCOMMAND_DELETE
54 APPCOMMAND_DWM_FLIP3D

參考資料

如果希望綁定為特殊按鍵

  • 新增 D:\SendKey.js
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

設定範例

  • CustomAppKey.reg
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\15]
"ShellExecute"="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe https://inbox.google.com/u/0/"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\16]
"Association"=".cda"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\17]
"ShellExecute"="C:\\Windows\\System32\\SnippingTool.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18]
"ShellExecute"="calc.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\7]
"ShellExecute"="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe https://www.google.com.tw/"
@cxw42
Copy link

cxw42 commented Jun 10, 2018

Thanks for the information on RegisteredApp and Association! Another blog post, and a Super User answer on the topic. (I am not affiliated with either.)

@jgrisham
Copy link

2024 update:

The blog post referenced in the "RegisteredApp" row of the table above ("Getting Vista to open my Inbox the way I want it to" posted on 2006-11-30 to the "A Hole In My Head" MSDN blog) now appears to be located here (or use this archived copy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment