Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #12  
Antiguo 25-11-2014
Avatar de aguml
aguml aguml is offline
Miembro
 
Registrado: may 2013
Posts: 885
Poder: 14
aguml Va por buen camino
Amigo el hook va fantastico, lo he modificado un poquitin y quedó así:

App:
Código PHP:
#include <vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

typedef void (*LPFuncion)(BOOL,HINSTANCE/*Redefiní la funcion*/);

TForm1 *Form1;
HMODULE Dll;
bool errorFunc=trueerrorDll=true;
LPFuncion Funcion=NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponentOwner)
   : 
TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ButtonColocarHookClick(TObject *Sender)
{
   
ColocarHook();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ButtonQuitarHookClick(TObject *Sender)
{
   
//desinstalamos el hook
   
Funcion(FALSE,NULL);

   
ButtonColocarHook->Enabled true;
   
ButtonQuitarHook->Enabled false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   
ColocarHook();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *SenderTCloseAction &Action)
{
   
//desinstalamos el hook
   
if(!errorFunc)
      
Funcion(FALSE,NULL);

   
//liberamos la memoria
   
if(!errorDll)
      
FreeLibrary(Dll);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ColocarHook()
{
   
//cargamos la Dll
   
Dll=LoadLibrary("DllHookKeyboard.dll");
   if(!
Dll){
      
ShowMessage("No se encontró la Dll: DllHookKeyboard.dll");
      
errorDll true;
   }else{
      
errorDll false;
      
//buscamos la funcion en la dll
      
Funcion = (LPFuncion)GetProcAddress(Dll"CreaHook");
      if(!
Funcion){
         
ShowMessage("ERROR, no se encontró la función: Crck");
         
errorFunc true;
      }else{
         
//ejecutamos la función
         
Funcion(TRUE,Dll);//instalamos el hook
         
ButtonColocarHook->Enabled false;
         
ButtonQuitarHook->Enabled true;
         
errorFunc false;
      }
   }

Dll:
Código PHP:
#include <windows.h>

#define OK -32767 //Necesario para el keylogger

HHOOK gancho;

#pragma argsused  

LRESULT CALLBACK Filtro(int nCodeWORD wParamDWORD lParam)
{
   if(
nCode == HC_ACTION){
     if((
GetKeyState(0x43) < 0) && GetAsyncKeyState(VK_CONTROL) == OK){ //si pulsamos [Ctl+C]
       
CloseClipboard();
       
OpenClipboard(0);
       
EmptyClipboard();
       
MessageBox(NULL,"Has intentado copiar al portapapeles con Ctrl+C","Atención"MB_OK MB_ICONINFORMATION);
     }
     else if((
GetKeyState(0x56) < 0) && GetAsyncKeyState(VK_CONTROL) == OK){ //si pulsamos [Ctl+V]
       
CloseClipboard();
       
MessageBox(NULL,"Has intentado pegar desde el portapapeles con Ctrl+V","Atención",MB_OK MB_ICONINFORMATION);
     }
   }
   return 
CallNextHookEx(gancho,nCode,wParam,lParam);
}

/*******************************************************/
/*FUNCIÓN PARA INSTALAR/DESINSTALAR EL HOOK DEL TECLADO*/
/*******************************************************/
extern "C" __declspec(dllexport__stdcall int CreaHook(BOOL InstalaHINSTANCE DLLInst)
{
   
int retval;

   if(
Instala==TRUE) {
      
gancho=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)Filtro,DLLInst,0);
      if(
gancho==NULL){
         
retval 0;
      }else{
         
retval 1;
      }
   }else{
      
CloseClipboard();
      
retval UnhookWindowsHookEx(gancho);
   }
   return 
retval;
}
//---------------------------------------------------------------------------

int WINAPI DllEntryPoint(HINSTANCE hinstunsigned long reasonvoidlpReserved)
{
   return 
1;

Ahora bien, lo que pones de los HotKeys a mi no me ha funcionado pero si me funciona usando esto:
http://docs.embarcadero.com/products...OnMessage.html

Por lo que puedo entender en el comentario del final del codigo dice que si no lo pongo yo handled a true será gestionado por otros manejadores y no veo que el haga nada al respecto si no lo maneja el y así lo dejé yo:

App.h:
Código PHP:
private:    // User declarations
   
TMessageEvent OldApplicationOnMessage;
   
void __fastcall AppMessage(tagMSG &Msgbool &Handled); 
App.cpp:
Código PHP:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   
OldApplicationOnMessage Application->OnMessage;
   
Application->OnMessage AppMessage;
   
RegistrarHotKeys();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
   
Application->OnMessage OldApplicationOnMessage;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::AppMessage(tagMSG &Msgbool &Handled)
{
   if(
Msg.message == WM_HOTKEY)
   {
      
//Comprobamos si se pulsó algún atajo de teclado

      
if( LOWORD(Msg.lParam) == MOD_CONTROL )
      {
         switch( 
HIWORD(Msg.lParam) )
         {
            case 
'L':
               
ButtonClic->Click();
               
Sleep(150);
               
Handled true;
               break;

            case 
'C':
               
ButtonClose->Click();
               
Handled true;
               break;

            case 
'D':
               
ButtonDisable->Click();
               
Handled true;
               break;

            case 
'A':
               
ButtonEnable->Click();
               
Handled true;
               break;

            case 
'M':
               
ButtonShow->Click();
               
Handled true;
               break;

            case 
'O':
               
ButtonHide->Click();
               
Handled true;
               break;

            case 
'X':
               
ButtonMaximize->Click();
               
Handled true;
               break;

            case 
'R':
               
ButtonRestore->Click();
               
Handled true;
               break;

            case 
'I':
               
ButtonMinimize->Click();
               
Handled true;
               break;

            case 
'S':
               
ButtonTopmost->Click();
               
Handled true;
               break;

            case 
'N':
               
ButtonNonTop->Click();
               
Handled true;
               break;

            case 
'E':
               
ButtonSendCaption->Click();
               
Handled true;
               break;

            case 
'F':
               if(
ButtonIntroHandle->Enabled == true)
                  
ButtonIntroHandle->Click();
               
Handled true;
               break;
         }
      }
   }

Así va perfecto pero no se si es lo mas correcto o no
Responder Con Cita
 



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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
como capturar pulsaciones del teclado y guardarlo en un archivo txt kurono Varios 25 15-01-2008 12:25:26
Hook de Teclado + DLL FeLiXxUcO C++ Builder 12 12-02-2006 19:59:53
capturar pulsaciones de teclado i_berbeu C++ Builder 3 08-02-2006 23:00:35
Hook de teclado! marceloalegre Varios 2 17-10-2005 00:59:47
Obtenert el handler de la ventana donde se han de enviar las pulsaciones del teclado ASAPLTDA API de Windows 0 07-04-2005 23:38:56


La franja horaria es GMT +2. Ahora son las 09:09:11.


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