我有一個字符串變量。現在我想在不使用剪貼板的情況下將字符串值存儲到另一個應用程序的控件中。我想手動做。發送文本到其他應用程序
我想我應該使用SendMessage(WM_SETTEXT)。你建議哪種方式(請舉例)?
我有一個字符串變量。現在我想在不使用剪貼板的情況下將字符串值存儲到另一個應用程序的控件中。我想手動做。發送文本到其他應用程序
我想我應該使用SendMessage(WM_SETTEXT)。你建議哪種方式(請舉例)?
當你的應用程序知道它發送字符串...
您可以根據需要將焦點設置到目標窗口/應用。
然後處理字符串中包含的每個字符以模擬它們的擊鍵。類似的東西(也基本準確地工作,像您期望的,但這個想法是在這裏...; O)):
for i := 1 to Length(yourstring) do
begin
keybd_event(Ord(yourstring[i]), 0, 0, 0); // key down
Sleep(10);
keybd_event(Ord(yourstring[i]), 0, 0 or KEYEVENTF_KEYUP, 0);/key up
Sleep(10);
end;
如果字符串大寫,......,你需要模擬的Shift,Ctrl ...
輸入多字節字符keybd_event:
procedure InsertText(text:string);
var i:integer;
j:integer;
ch:byte;
str:string;
begin
i:=1;
while i<=Length(text) do
begin
ch:=byte(text[i]);
if Windows.IsDBCSLeadByte(ch) then
begin
Inc(i);
str:=inttostr(MakeWord(byte(text[i]), ch));
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);
j:=1;
while j<=Length(str) do
begin
keybd_event(96+strtoint(str[j]), MapVirtualKey(96+strtoint(str[j]), 0), 0, 0);
keybd_event(96+strtoint(str[j]), MapVirtualKey(96+strtoint(str[j]), 0), 2, 0);
j:=j+1;
end;
keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
end
else begin
keybd_event(VkKeyScan(text[i]),0,0,0);
keybd_event(VkKeyScan(text[i]),0,2,0);
end;
Inc(i);
end;
end;
依賴於其他應用程序。它是哪個應用程序?該應用程序中的哪個控件是您的目標? –
好的,所以你實際上並不想嚴格意義上粘貼*任何東西,也就是使用剪貼板? –
首先,您需要目標編輯控件的窗口句柄。 –