Показать сообщение отдельно
Старый 21.06.2015, 22:32   #10
Местный
 
Аватар для Yegor
 
Регистрация: 05.04.2009
Сообщений: 1,436
Сказал Спасибо: 306
Имеет 122 спасибок в 98 сообщенях
Yegor пока неопределено
По умолчанию

Пример вставки текста в окно л2:

PHP код:
procedure PostKeyExHWND(hWindowHWndkeyWord; const shiftTShiftStatespecialkeyBoolean);
 {************************************************************
 * 
Procedure PostKeyEx
 
*
 * 
Parameters:
 *  
hWindowtarget window to be send the keystroke
 
*  key    virtual keycode of the key to send. For printable
 
*           keys this is simply the ANSI code (Ord(character)).
 *  
shift  state of the modifier keysThis is a setso you
 
*           can set several of these keys (shiftcontrolalt,
 *           
mouse buttonsin tandemThe TShiftState type is
 
*           declared in the Classes Unit.
 *  
specialkeynormally this should be FalseSet it to True to
 
*           specify a key on the numeric keypad, for example.
 *           If 
this parameter is truebit 24 of the lparam for
 *           
the posted WM_KEYmessages will be set.
 * 
Description:
 *  
This procedure sets up Windows key state array to correctly
 
*  reflect the requested pattern of modifier keys and then posts
 
*  a WM_KEYDOWN/WM_KEYUP message pair to the target windowThen
 
*  Application.ProcessMessages is called to process the messages
 
*  before the keyboard state is restored.
 * 
Error Conditions:
 *  
May fail due to lack of memory for the two key state buffers.
 *  
Will raise an exception in this case.
 * 
NOTE:
 *  
Setting the keyboard state will not work across applications
 
*  running in different memory spaces on Win32 unless AttachThreadInput
 
*  is used to connect to the target thread first.
 *
Created02/21/96 16:39:00 by PBelow
 
************************************************************}

type
 TBuffers 
= array [0..1of TKeyboardState;
var
 
pKeyBuffers: ^TBuffers;
 
lParamLongInt;
begin
 
(* check if the target window exists *)
  if 
IsWindow(hWindowthen
  begin
   
(* set local variables to default values *)
   
//pKeyBuffers := nil;
   
lParam := MakeLong(0MapVirtualKey(key0));

   (* 
modify lparam if special key requested *)
   if 
specialkey then
     lParam 
:= lParam or $1000000;

   (* 
allocate space for the key state buffers *)
   New(
pKeyBuffers);
   try
     (* 
Fill buffer 1 with current state so we can later restore it.
        
Null out buffer 0 to get a "no key pressed" state. *)
     
GetKeyboardState(pKeyBuffers^[1]);
     
FillChar(pKeyBuffers^[0], SizeOf(TKeyboardState), 0);

     (* 
set the requested modifier keys to "down" state in the buffer*)
     if 
ssShift in shift then
       pKeyBuffers
^[0][VK_SHIFT] := $80;
     if 
ssAlt in shift then
     begin
       
(* Alt needs special treatment since a bit in lparam needs also be set *)
       
pKeyBuffers^[0][VK_MENU] := $80;
       
lParam := lParam or $20000000;
     
end;
     if 
ssCtrl in shift then
       pKeyBuffers
^[0][VK_CONTROL] := $80;
     if 
ssLeft in shift then
       pKeyBuffers
^[0][VK_LBUTTON] := $80;
     if 
ssRight in shift then
       pKeyBuffers
^[0][VK_RBUTTON] := $80;
     if 
ssMiddle in shift then
       pKeyBuffers
^[0][VK_MBUTTON] := $80;

     (* 
make out new key state array the active key state map *)
     
SetKeyboardState(pKeyBuffers^[0]);
     (* 
post the key messages *)
     if 
ssAlt in Shift then
     begin
       PostMessage
(hWindowWM_SYSKEYDOWNkeylParam);
       
PostMessage(hWindowWM_SYSKEYUPkeylParam or integer($C0000000));
     
end
     
else
     
begin
       PostMessage
(hWindowWM_KEYDOWNkeylParam);
       
PostMessage(hWindowWM_KEYUPkeylParam or integer($C0000000));
     
end;
     (* 
process the messages *)
     
//ad.ToLogFile('Before ProcessMessages PostKeyExHWND');
     
Application.ProcessMessages;

     (* 
restore the old key state map *)
     
SetKeyboardState(pKeyBuffers^[1]);
   finally
     (* 
free the memory for the key state buffers *)
     if 
pKeyBuffers <> nil then
       Dispose
(pKeyBuffers);
    
end; { If }
  
end;
end; { PostKeyEx }

function 
InsertText(textstringwinHandleHWND): boolean;
var
  
iword;
  
ThreadIDmycardinal;
  
hFocusedWndHWND;
  
chinteger;
begin
  ThreadID
:= GetWindowThreadProcessId(winHandlenil);
  
my:= GetCurrentThreadId;
  
AttachThreadInput(ThreadIDmytrue);
  
hFocusedWnd:= GetFocus;

  for 
i:= 1 to Length(text) do
  
begin
    ch
:= ord(text[i]);
    
PostMessage(hFocusedWndWM_CHARch1);
  
end;
  
AttachThreadInput(ThreadIDmyfalse);
  
Result:= true;
  
Sleep(300);
end;



....
var
  
clientHWNDHWND;
....
clientHWND:= FindWindow('l2UnrealWWindowsViewportWindow'nil);

InsertText(LoginclientHWND);
Sleep(2000);
PostKeyExHWND(clientHWNDVK_TAB, [], false);
Sleep(1000);
InsertText(PasswordclientHWND);
Sleep(2000);
PostKeyExHWND(clientHWNDVK_RETURN, [], false); 
__________________
Продажа чистых аккаунтов 4G, L2 EU, AARu, AA EU, Aion EU, Tera RU, Tera EU (ICQ 594297609)
Продажа VK авторег аккаунтов (ICQ 594297609)
Yegor вне форума   Ответить с цитированием
За это сообщение Yegor нажился спасибкой от: