近日来写程序,要用到键盘模拟操作,写了一个调用单元,供大家学习、使用。
unit dbyoung_Keyboard;
interface
uses Windows;
{
引用代码:
KeyDown_SendInput_OneKey(VK_SCROLL);
KeyDown_SendInput_OneKey(VK_NUMLOCK);
KeyDown_SendInput_OneKey(VK_CAPITAL);
KeyDown_SendInput_TwoKey(VK_LCONTROL,VK_ESCAPE);
KeyDown_WINIO_OneKey(VK_SCROLL);
KeyDown_WINIO_OneKey(VK_NUMLOCK);
KeyDown_WINIO_OneKey(VK_CAPITAL);
}
procedure KeyDown_WINIO_OneKey(vKeyCode: Cardinal);
procedure KeyDown_SendInput_OneKey(vKeyCode: Integer); //单键
procedure KeyDown_SendInput_TwoKey(vKeyCode1, vKeyCode2: Cardinal); //复合键
implementation
procedure KeyDown_SendInput_OneKey(vKeyCode: Integer);
procedure KeyDown(wvk: Integer);
var
sInput : tInput;
begin
sInput.Itype := INPUT_KEYBOARD;
sInput.ki.dwflags := 0;
sInput.ki.wScan := 0;
sInput.ki.wvk := wvk;
SendInput(1, sInput, SizeOf(tInput));
end;
procedure KeyUp(wvk: Integer);
var
sInput : tInput;
begin
sInput.Itype := INPUT_KEYBOARD;
sInput.ki.dwflags := KEYEVENTF_KEYUP;
sInput.ki.wvk := wvk;
sInput.ki.wScan := 0;
SendInput(1, sInput, SizeOf(tInput));
end;
begin
KeyDown(vKeyCode);
KeyUp(vKeyCode);
end;
procedure KeyDOWN_SendInput_TwoKey(vKeyCode1, vKeyCode2: Cardinal);
var
sInput : array[0..3] of tInput;
begin
sInput[0].itype := INPUT_KEYBOARD;
sInput.itype := INPUT_KEYBOARD;
sInput.itype := INPUT_KEYBOARD;
sInput.itype := INPUT_KEYBOARD;
sInput[0].ki.wVk := vKeyCode1;
sInput.ki.wVk := vKeyCode1;
sInput.ki.wVk := vKeyCode2;
sInput.ki.wVk := vKeyCode2;
sInput.ki.dwFlags := KEYEVENTF_KEYUP;
sInput.ki.dwFlags := KEYEVENTF_KEYUP;
SendInput(4, sInput[0], sizeof(sInput[0]));
end;
function EnableDebugPr