我需要在 Delphi 中模拟多媒体键(如播放/暂停、上一首/下一首、快退/前进等)的按下。我可以使用下面的代码轻松模拟“普通”键:
keybd_event(VK_SPACE,0, 0, 0);
keybd_event(VK_SPACE,0, KEYEVENTF_KEYUP, 0);
另外,我找到了 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.
我找到了提高音量的扫描码:
通码:E0、32 断码:E0、F0、32
我试过了:
keybd_event(0,$32, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(0,$32, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP, 0);
但也没有运气(这必须模拟 E0 32 E0 32,没有 F0)。MSDN 还说 bVk 必须是 [1..254],我使用 0 因为我没有在关键代码列表中找到任何合适的东西。