Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   API de Windows (https://www.clubdelphi.com/foros/forumdisplay.php?f=7)
-   -   Pegar texto en un documento desde Delphi (https://www.clubdelphi.com/foros/showthread.php?t=25416)

mitxael 21-09-2005 23:59:50

Pegar texto en un documento desde Delphi
 
Si, lo que quiero saber es como puedo pegar texto desde mi aplicacion en un documento, pongamos el word.
Esto surgue debido a :
Tengo una laptop con teclado en italiano (tastiera:D), y el unico problema que le encuentro es la "ñ", y se me ocurrio la graciosa idea de hacer un programa que pegue dicha letra en el documento en el que este trabajando mediante una hotkey (win+n), hasta el momento logre hacer un programa que se ejecute invisiblemente, ponga la "ñ" en el portapapeles y lo unico que tengo que hacer es poner PEGAR en el documento, lo que quiero es algo ms facil, que la letra se pegue sola.

Empezemos con los apis!!!!!

rounin 23-09-2005 10:52:55

May be it's simpler to install a global hook on messages and
and replace Win+n on n con tilde inside WM_CHAR processing?

Something like this:

Código Delphi [-]
{************* HookDef.pas **************}
 
 unit HookDef;
 
 interface
 
 const
   NConTildeMappingName: PChar = 'n_con_tilde';
 
 type
   PNConTildeData = ^TNConTildeData;
   TNConTildeData = record
     hHook: Longint;
   end;
 
 implementation
 
 end.
 
 {*************** Hook.dll ****************}
 
 library hook;
 
 uses
   Windows,
   Messages,
   HookDef in 'HookDef.pas';
 
 type
   PGlobalHookData = ^TGlobalHookData;
   TGlobalHookData = TNConTildeData;
 
 var
   HookMappingName: PChar absolute NConTildeMappingName;
 
 {------------------------------------------------------------------------------}
 
 var
   Data: PGlobalHookData;
   hMapping: THandle;
 
 const
   N_CON_TILDE = $F1;
   N_MAYUSC_CON_TILDE = $D1;
 
   VK_WIN = $5B;
 
 function HookProc(nCode, wParam, lParam: Longint): Longint; stdcall;
 var
   RemovalFlag: Longint absolute wParam;
   Msg: PMsg absolute lParam;
   WinKey_State: Byte;
 begin
   if nCode = HC_ACTION then
   begin
     if (Msg.message = WM_CHAR) then
     // wParam = chCharCode, lParam = lKeyData
     begin
       WinKey_State := GetKeyState(VK_WIN);
       if (WinKey_State and $80) > 0 then
       begin
         if (Msg^.wParam = Ord('n')) then Msg^.wParam := N_CON_TILDE;
         if (Msg^.wParam = Ord('N')) then Msg^.wParam := N_MAYUSC_CON_TILDE;
       end;
     end;
   end;
   Result := CallNextHookEx(Data^.hHook, nCode, wParam, lParam);
 end;
 
 function InstallHook: PGlobalHookData; stdcall;
 begin
   Data^.hHook := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, HInstance, 0);
   if Data^.hHook <> 0 then
     Result := Data
   else
     Result := nil;
 end;
 
 function UninstallHook: Boolean; stdcall;
 begin
   Result := UnhookWindowsHookEx(Data^.hHook);
   Data^.hHook := 0;
 end;
 
 procedure OpenGlobalData;
 begin
   hMapping := CreateFileMapping(INVALID_HANDLE_VALUE, nil,
     PAGE_READWRITE, 0, SizeOf(TGlobalHookData), HookMappingName);
   if hMapping = 0 then Exit;
   Data:= MapViewOfFile(hMapping, FILE_MAP_ALL_ACCESS, 0, 0, SizeOf(TGlobalHookData));
   if Data = nil then CloseHandle(hMapping);
 end;
 
 procedure CloseGlobalData;
 begin
   UnmapViewOfFile(Data);
   CloseHandle(hMapping);
 end;
 
 procedure DLLEntryPoint(dwReason: DWord); register;
 begin
   case dwReason of
     DLL_PROCESS_ATTACH: OpenGlobalData;
     DLL_PROCESS_DETACH: CloseGlobalData;
   end;
 end;
 
 exports
   InstallHook,
   UninstallHook;
 
 {
 function InstallHook: PGlobalHookData; stdcall; external 'hook.dll';
 function UninstallHook: Boolean; stdcall; external 'hook.dll';
 }
 
 begin
   DLLProc:= @DLLEntryPoint;
   DLLEntryPoint(DLL_PROCESS_ATTACH);
 end.
 
 {*******************************************}

mitxael 23-09-2005 22:20:22

How can I execute it?
I attach it to an application form, but i don't know how execute it :S

rounin 24-09-2005 13:14:31

File 'hook.dpr' is source of the DLL.
You need open it using "Open project" and compile it.
The result will be hook.dll

The main application should contain the following code:
(When the main application installs global hook,
the hook.dll will be loaded on every application)

Código Delphi [-]
 
// uses HookDef
function InstallHook: PNConTildeData; stdcall; external 'hook.dll';
function UninstallHook: Boolean; stdcall; external 'hook.dll';
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  {FHookData := }InstallHook; 
end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  UninstallHook; 
end;

I have attached the working example.

rounin 24-09-2005 13:18:30

The example

vtdeleon 24-09-2005 15:47:55

Helo

rounin
, thank you very much for your example:D. That had opened my eyes for a application. This resolve this post:http://www.clubdelphi.com/foros/showthread.php?t=24334

mitxael 25-09-2005 09:15:31

Resuelto
 
Resolvi el problema, simulè la presion de ciertas teclas desde el programa; puse la ñ en el portapapeles,luego simulè un "alt+tab" y luego un "crtl+v" y la ñ aparece en el programa en el que estemos y donde el cursor este ubicado...en cualquier programa...asi de simple....claro, yo uso el atajo de teclas "win+n" para sacar la ñ, eso facilmente ya que tengo instalado el aston 1.9 que maneja hotkeys, y solo le asigne el atajo al programa "ascii.exe" que adjunto a continuaciòn.


La franja horaria es GMT +2. Ahora son las 17:54:58.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi