MSDN声明keybd_event已被SendInput取代.在重写期间,我切换到使用SendInput ... 除了尝试发送Alt-key组合时,这很好.在Win7 64位系统上(尚未在其他地方尝试过),在目标应用程序中显示击键之前,发送Alt键会导致长时间延迟.
有什么想法吗?或者我做错了什么?现在,我已经回到了keybd_event - 下面的第二个版本.
//Keyboard input from this version appears only after a ~4-5 second
//time lag...
procedure SendAltM;
var
KeyInputs: array of TInput;
KeyInputCount: Integer;
//--------------------------------------------
procedure KeybdInput(VKey: Byte; Flags: DWORD);
begin
Inc(KeyInputCount);
SetLength(KeyInputs, KeyInputCount);
KeyInputs[KeyInputCount - 1].Itype := INPUT_KEYBOARD;
with KeyInputs[KeyInputCount - 1].ki do
begin
wVk := VKey;
wScan := MapVirtualKey(wVk, 0);
dwFlags := KEYEVENTF_EXTENDEDKEY;
dwFlags := Flags or dwFlags;
time := 0;
dwExtraInfo := 0;
end;
end;
begin
KeybdInput(VK_MENU, 0); // Alt
KeybdInput(Ord('M'), …Run Code Online (Sandbox Code Playgroud)