举例://模拟 alt + F
keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(70,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(70,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(70,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(70,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0);
解决方案 »
- 新手 菜鸟 刚注册没分 数据库备份问题
- 有谁知道,象 delphi 那样子的,分开的两个窗口 之间有联系吗?50分求答案
- 简单问题:DateTimePicker1 中的值 赋予一个 string
- 用installshield制作Delphi数据库安装程序的问题?(采用ADO访问access)
- 雙向鏈表求助
- 请问 哪里可以下载到 InterBase6.0呀?
- DELPHI5 中 SERVICE 和 SERVICE APPLICATION 这两个工程有什么区别?
- 如何控制Excel?
- delphi怎样读取系统的字体
- 哪位大侠知道DBChart的预揽、打印命令?
- 有谁做过打印控件的预览??
- 伴水老师,您在吗?进来好吗?今天在线等待
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
ParametersbVkSpecifies a virtual-key code. The code must be a value in the range 1 to 254. bScanSpecifies a hardware scan code for the key. dwFlagsA 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: Value Meaning
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.
dwExtraInfoSpecifies an additional 32-bit value associated with the key stroke. Return ValuesThis function has no return value.
http://kingron.myetang.com/zsfunc03.htm(*//
标题:模拟系统按键
说明:支持组合键;不支持部分系统热键(如:Ctrl+Shift+Del...)
设计:Zswang
日期:2002-01-24
支持:[email protected]
//*)///////Begin Source
procedure SendKey(const mKey: Word; mShiftState: TShiftState;
mCount: Integer = 1); { 模拟系统按键;mCount指定按键次数 }
const
cExtended: set of Byte = [VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_HOME,
VK_END, VK_PRIOR, VK_NEXT, VK_INSERT, VK_DELETE]; procedure pKeyboardEvent(mKey, mScanCode: Byte; mFlags: Longint);
var
vKeyboardMsg: TMsg;
begin
keybd_event(mKey, mScanCode, mFlags, 0);
while PeekMessage(vKeyboardMsg, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE) do
begin
TranslateMessage(vKeyboardMsg);
DispatchMessage(vKeyboardMsg);
end;
end; { pKeyboardEvent } procedure pSendKeyDown(mKey: Word; mGenUpMsg: Boolean);
var
vScanCode: Byte;
vNumState: Boolean;
vKeyBoardState: TKeyboardState;
begin
if (mKey = VK_NUMLOCK) then begin
vNumState := ByteBool(GetKeyState(VK_NUMLOCK) and 1);
GetKeyBoardState(vKeyBoardState);
if vNumState then
vKeyBoardState[VK_NUMLOCK] := (vKeyBoardState[VK_NUMLOCK] and not 1)
else vKeyBoardState[VK_NUMLOCK] := (vKeyBoardState[VK_NUMLOCK] or 1);
SetKeyBoardState(vKeyBoardState);
Exit;
end; vScanCode := Lo(MapVirtualKey(mKey, 0));
if (mKey in cExtended) then begin
pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY);
if mGenUpMsg then
pKeyboardEvent(mKey, vScanCode,
KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP)
end else begin
pKeyboardEvent(mKey, vScanCode, 0);
if mGenUpMsg then pKeyboardEvent(mKey, vScanCode, KEYEVENTF_KEYUP);
end;
end; { pSendKeyDown } procedure pSendKeyUp(mKey: Word);
var
vScanCode: Byte;
begin
vScanCode := Lo(MapVirtualKey(mKey, 0));
if mKey in cExtended then
pKeyboardEvent(mKey, vScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
else pKeyboardEvent(mKey, vScanCode, KEYEVENTF_KEYUP);
end; { pSendKeyUp }var
I: Integer;
begin
for I := 1 to mCount do begin
if ssShift in mShiftState then pSendKeyDown(VK_SHIFT, False);
if ssCtrl in mShiftState then pSendKeyDown(VK_CONTROL, False);
if ssAlt in mShiftState then pSendKeyDown(VK_MENU, False);
pSendKeyDown(mKey, True);
if ssShift in mShiftState then pSendKeyUp(VK_SHIFT);
if ssCtrl in mShiftState then pSendKeyUp(VK_CONTROL);
if ssAlt in mShiftState then pSendKeyUp(VK_MENU);
end;
end; { SendKey }
///////End Source///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
SendKey(VK_F4, [ssAlt]);
end;
///////End Demo
winexec('notepad',1); //把记事本窗口激活
setforegroundwindow(findwindow(nil,'无标题 - 记事本')); //模拟输入 'abc'
keybd_event(65,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(65,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0); keybd_event(66,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(66,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0); keybd_event(67,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(67,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0); //模拟 alt + F 打开文件菜单
keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(70,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(70,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0);
keybd_event(VK_MENU,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0); //模拟输入 按 s 保存
keybd_event(83,0,KEYEVENTF_EXTENDEDKEY or 0,0);
keybd_event(83,0,KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,0);
//至于按键的 vkcode,你自己编个工具在form的 onkeydown里得到