我需要在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.
我找到了Volume Up的扫描码:
制作代码: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,因为我没找到任何合适的密钥代码列表。
答案 0 :(得分:5)
在Delphi XE3中它适用于我:
keybd_event(VK_VOLUME_UP {$AF},0, 0, 0);
keybd_event(VK_VOLUME_UP,0, KEYEVENTF_KEYUP, 0);
如果未在Delphi版本中声明这些常量,请查看the table here