Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > API de Windows
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 21-09-2005
Avatar de mitxael
mitxael mitxael is offline
Miembro
 
Registrado: sep 2005
Ubicación: Cusco
Posts: 11
Poder: 0
mitxael Va por buen camino
Question 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), 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!!!!!
Responder Con Cita
  #2  
Antiguo 23-09-2005
rounin rounin is offline
Miembro
 
Registrado: sep 2005
Posts: 43
Poder: 0
rounin Va por buen camino
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.
 
 {*******************************************}

Última edición por dec fecha: 23-09-2005 a las 11:03:55. Razón: ¡¡Encerrad el código fuente entre las etiquetas [DELPHI] ... [/DELPHI]!!
Responder Con Cita
  #3  
Antiguo 23-09-2005
Avatar de mitxael
mitxael mitxael is offline
Miembro
 
Registrado: sep 2005
Ubicación: Cusco
Posts: 11
Poder: 0
mitxael Va por buen camino
Talking

How can I execute it?
I attach it to an application form, but i don't know how execute it :S
Responder Con Cita
  #4  
Antiguo 24-09-2005
rounin rounin is offline
Miembro
 
Registrado: sep 2005
Posts: 43
Poder: 0
rounin Va por buen camino
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.

Última edición por rounin fecha: 24-09-2005 a las 18:12:26.
Responder Con Cita
  #5  
Antiguo 24-09-2005
rounin rounin is offline
Miembro
 
Registrado: sep 2005
Posts: 43
Poder: 0
rounin Va por buen camino
The example

Última edición por rounin fecha: 26-10-2007 a las 15:03:03.
Responder Con Cita
  #6  
Antiguo 24-09-2005
Avatar de vtdeleon
vtdeleon vtdeleon is offline
Miembro
 
Registrado: abr 2004
Ubicación: RD & USA
Posts: 3.236
Poder: 24
vtdeleon Va por buen camino
Helo

rounin
, thank you very much for your example. That had opened my eyes for a application. This resolve this post:http://www.clubdelphi.com/foros/showthread.php?t=24334
__________________
Van Troi De León
(Not) Guía, Code vB:=Delphi-SQL, ¿Cómo?
Viajar en el tiempo no es teóricamente posible, pues si lo fuera, ya estarían aqui contándonos al respecto!
Responder Con Cita
  #7  
Antiguo 25-09-2005
Avatar de mitxael
mitxael mitxael is offline
Miembro
 
Registrado: sep 2005
Ubicación: Cusco
Posts: 11
Poder: 0
mitxael Va por buen camino
Thumbs up 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.

Última edición por mitxael fecha: 25-09-2005 a las 09:19:06.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 23:54:26.


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
Copyright 1996-2007 Club Delphi