在Delphi中模拟多媒体按键

use*_*897 3 delphi multimedia key simulate scancodes

我需要在Delphi中模拟按多媒体键(如播放/暂停,上一首/下一首曲目,快退/前进等).我可以使用下一个代码轻松模拟"普通"键:

keybd_event(VK_SPACE,0, 0, 0);
keybd_event(VK_SPACE,0, KEYEVENTF_KEYUP, 0);
Run Code Online (Sandbox Code Playgroud)

另外,我找到了MAKE/BREAK代码列表,但我该怎么办呢?

MSDN说:

VOID keybd_event(
    BYTE bVk,   // virtual-key code
    BYTE bScan, // hardware scan code
    DWORD dwFlags,  // flags specifying various function options
    DWORD dwExtraInfo   // additional data associated with keystroke
   );   
bVk - Specifies a virtual-key code. The code must be a value in the range 1 to 254. 
bScan - Specifies a hardware scan code for the key. 
dwFlags - A set of flag bits that specify various aspects of function operation.
    An application can use any combination of the following predefined constant
    values to set the flags: 
    KEYEVENTF_EXTENDEDKEY - If specified, the scan code was preceded by a 
        prefix byte having the value 0xE0 (224).
    KEYEVENTF_KEYUP If specified, the key is being released. If 
        not specified, the key is being depressed.
dwExtraInfo - Specifies an additional 32-bit value associated with the key stroke. 
Run Code Online (Sandbox Code Playgroud)

我找到了Volume Up的扫描码:

使代码:E0,32中断代码:E0,F0,32

我试过了:

keybd_event(0,$32, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(0,$32, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0);
Run Code Online (Sandbox Code Playgroud)

但也没有运气(这必须模拟E0 32 E0 32,没有F0).MSDN也说bVk必须是[1..254],而我使用0是因为我没有在密钥代码列表中找到任何合适的东西.

MBo*_*MBo 5

它适用于Delphi XE3:

keybd_event(VK_VOLUME_UP {$AF},0, 0, 0);
keybd_event(VK_VOLUME_UP,0, KEYEVENTF_KEYUP, 0);
Run Code Online (Sandbox Code Playgroud)

如果这些常量未在Delphi版本中声明,请查看此处的表格