procedure PostKeyEx(hWindow : HWnd; Key : Word; const Shift : TShiftState; SpecialKey : Boolean);
type
TBuffers = Array[0..1] of TKeyboardState;
var
pKeyBuffers : ^TBuffers;
lParam : LongInt;
begin
if IsWindow(hWindow) then
begin
pKeyBuffers := nil;
lParam := MakeLong(0, MapVirtualkey(Key,0));
if SpecialKey then lParam := lParam or $1000000;
New(pKeyBuffers);
try
GetKeyboardState(pKeyBuffers^[1]);
FillChar(pKeyBuffers^[0],SizeOf(TKeyboardState), 0);
if ssShift in Shift then pKeyBuffers^[0][VK_SHIFT] := $80;
if ssAlt in Shift then
begin
pKeyBuffers^[0][VK_MENU] := $80;
lParam := lParam or $20000000;
end;
if ssCtrl in Shift then pKeyBuffers^[0][VK_CONTROL] := $80;
if ssRight in Shift then pKeyBuffers^[0][VK_RBUTTON] := $80;
if ssLeft in Shift then pKeyBuffers^[0][VK_LBUTTON] := $80;
if ssMiddle in Shift then pKeyBuffers^[0][VK_MBUTTON] := $80;
SetKeyboardState(pKeyBuffers^[0]);
if ssAlt in Shift then
begin
PostMessage(hWindow, WM_SYSKEYDOWN, Key, lParam);
PostMessage(hWindow, WM_SYSKEYUP, Key, lParam or $C0000000);
end
else
begin
PostMessage(hWindow, WM_KEYDOWN, Key, lParam);
PostMessage(hWindow, WM_KEYUP, Key, lParam or $C0000000);
end;
Application.ProcessMessages;
SetKeyboardState(pKeyBuffers^[1]);
finally
if pKeyBuffers <> nil then Dispose(pKeybuffers);
end;
end;
end;
한번 참조해보세요...
procedure PostKeyEx(hWindow : HWnd; Key : Word; const Shift : TShiftState; SpecialKey : Boolean);
type
TBuffers = Array[0..1] of TKeyboardState;
var
pKeyBuffers : ^TBuffers;
lParam : LongInt;
begin
if IsWindow(hWindow) then
begin
pKeyBuffers := nil;
lParam := MakeLong(0, MapVirtualkey(Key,0));
if SpecialKey then lParam := lParam or $1000000;
New(pKeyBuffers);
try
GetKeyboardState(pKeyBuffers^[1]);
FillChar(pKeyBuffers^[0],SizeOf(TKeyboardState), 0);
if ssShift in Shift then pKeyBuffers^[0][VK_SHIFT] := $80;
if ssAlt in Shift then
begin
pKeyBuffers^[0][VK_MENU] := $80;
lParam := lParam or $20000000;
end;
if ssCtrl in Shift then pKeyBuffers^[0][VK_CONTROL] := $80;
if ssRight in Shift then pKeyBuffers^[0][VK_RBUTTON] := $80;
if ssLeft in Shift then pKeyBuffers^[0][VK_LBUTTON] := $80;
if ssMiddle in Shift then pKeyBuffers^[0][VK_MBUTTON] := $80;
SetKeyboardState(pKeyBuffers^[0]);
if ssAlt in Shift then
begin
PostMessage(hWindow, WM_SYSKEYDOWN, Key, lParam);
PostMessage(hWindow, WM_SYSKEYUP, Key, lParam or $C0000000);
end
else
begin
PostMessage(hWindow, WM_KEYDOWN, Key, lParam);
PostMessage(hWindow, WM_KEYUP, Key, lParam or $C0000000);
end;
Application.ProcessMessages;
SetKeyboardState(pKeyBuffers^[1]);
finally
if pKeyBuffers <> nil then Dispose(pKeybuffers);
end;
end;
end;