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=true, errorDll=true;
LPFuncion Funcion=NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: 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 *Sender, TCloseAction &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 nCode, WORD wParam, DWORD 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 Instala, HINSTANCE 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 hinst, unsigned long reason, void* lpReserved)
{
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 &Msg, bool &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 &Msg, bool &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