张志峰的博客

水滴石川,积少成多。

导航

模拟键盘动作, 模拟鼠标动作

Posted on 2018-01-16 11:07  ╰★张志峰★╮  阅读(351)  评论(0编辑  收藏  举报

keybd_event(TextToShortCut('ctrl+s'), 0, 0, 0);

 

LockWindowUpdate(Self.Handle);
try
GetCursorPos(OldPt);
NewPt:=Point(0, 0);
Windows.ClientToScreen(Application.Handle, NewPt);
SetCursorPos(NewPt.X, NewPt.Y);
mouse_event(MOUSEEVENTF_LEFTDOWN, NewPt.X, NewPt.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, NewPt.X, NewPt.Y, 0, 0);
SetCursorPos(NewPt.X-10, NewPt.Y-10);
mouse_event(MOUSEEVENTF_LEFTDOWN, NewPt.X-10, NewPt.Y-10, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, NewPt.X-10, NewPt.Y-10, 0, 0);
SetCursorPos(OldPt.X, OldPt.Y);
finally
LockWindowUpdate(0);
end;