给你一段模拟特殊按键的代码试试,通过SetShiftState()来做,例如SetShiftState(VK_MENU,TRUE);
procedure KeybdEvent (KeyCode: Byte; Flags: DWORD);
begin
Keybd_Event(KeyCode, MapVirtualKey(KeyCode, 0), Flags, 0);
end;
procedure SetShiftState (Key: Byte; Down: Boolean);
var
KeyState: Boolean;
Flags: DWORD;
begin
KeyState := GetAsyncKeyState(Key) and $8000<>0;
if (KeyState and Down) or ((not KeyState)and(not Down)) then Exit;
if Down then Flags := 0 else Flags := KEYEVENTF_KEYUP;
KeybdEvent(Key,Flags);
end;
procedure SendKey (KeySym: Char; KeyDown: Boolean; bIsWinNT: Boolean);
var
KeyVal: SmallInt;
KeyCode, KeyMask: Byte;
LShift,RShift,Ctrl,Alt, CapsLock: Boolean;
Flags: DWORD;
begin
KeyVal := VkKeyScan(Char(Byte(KeySym) and $FF));
KeyCode := LOBYTE(KeyVal);
KeyMask := HIBYTE(KeyVal);
if KeyCode=$FF then Exit;
CapsLock := (GetAsyncKeyState(VK_CAPITAL) and $8000)<>0;
if CapsLock then KeyMask := KeyMask xor 1;
if bIsWinNT then
begin
LShift := (GetAsyncKeyState(VK_LSHIFT) and $8000) <> 0;
RShift := (GetAsyncKeyState(VK_RSHIFT) and $8000) <> 0;
SetShiftState(VK_RSHIFT, FALSE);
SetShiftState(VK_LSHIFT, FALSE);
SetShiftState(VK_SHIFT, (KeyMask and $01)<>0);
Ctrl := (GetAsyncKeyState(VK_LCONTROL) and $8000) <> 0;
if (not Ctrl) then SetShiftState(VK_LCONTROL,(KeyMask and $02)<>0);
Alt := (GetAsyncKeyState(VK_LMENU) and $8000) <> 0;
if (not Alt) then SetShiftState(VK_LMENU,(KeyMask and $04)<>0);
end else
begin
LShift := (GetAsyncKeyState(VK_SHIFT) and $8000) <> 0;
RShift := FALSE;
SetShiftState (VK_SHIFT, (KeyMask and $01)<>0);
Ctrl := (GetAsyncKeyState(VK_CONTROL) and $8000) <> 0;
if (not Ctrl) then SetShiftState(VK_CONTROL, (Keymask and $02)<>0);
Alt := (GetAsyncKeyState(VK_MENU) and $8000) <> 0;
if (not Alt) then SetShiftState(VK_MENU,(KeyMask and $04)<>0);
end;
if KeyDown then Flags := 0 else Flags := KEYEVENTF_KEYUP;
KeybdEvent(KeyCode and $FF,Flags);
if bIsWinNT then
begin
SetShiftState(VK_LSHIFT, LShift);
SetShiftState(VK_RSHIFT, RSHIFT);
SetShiftState(VK_LCONTROL, CTRL);
SetShiftState(VK_LMENU, ALT);
end else
begin
SetShiftState(VK_SHIFT, LSHIFT);
SetShiftState(VK_CONTROL, CTRL);
SetShiftState(VK_MENU, ALT);
end;
end;
个人认为:自己写代码才是王道,用控件只是辅助。[
]