SendMessage之前加一句 SetForegroundWindow(Wnd);<br>举例:<br>//在记事本中输入TAB键<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> Wnd: HWND;<br>begin<br><br> Wnd := FindWindow('notepad',nil);<br> if Wnd <> 0 then<br> begin<br> SetForegroundWindow(Wnd);<br> keybd_event(VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0);<br> keybd_event(VK_TAB, MapVirtualKey(VK_TAB, 0), KEYEVENTF_KEYUP, 0);<br> end;<br><br>end;