【发布时间】:2014-04-22 09:22:34
【问题描述】:
我需要在 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 是因为我没有在关键代码列表中找到任何合适的内容。
【问题讨论】:
-
为什么需要这样做?我确定有更好的解决方案吗?为什么这么多人认为伪造输入是问题的解决方案?
-
你试过 VK_VOLUME_UP = $AF 吗?
-
我正在编码红外遥控器,所以我真的需要伪造输入 :)
-
你确定?您可以在不伪造输入的情况下向应用发送彩信。
-
不知道是不是更通用。可能是。无论如何,不要使用
keybd_event。使用SendInput。SendInput的文档解释了原因。
标签: delphi key multimedia simulate scancodes