Hook al ratón.

(1/2) > >>

fary:
Este tema surgió en base a una pregunta de Mester que quería saber la posición del ratón en la pantalla sin hacer mucho uso de la memoria del ordenador. Creo que la forma de que consuma menos recursos es mediante hooks, aquí el ejemplo...

Código
// Hook al Ratón
 
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
 
LRESULT CALLBACK LowLevelMouseProc(int    nCode, WPARAM wParam, LPARAM lParam)
{
   PMSLLHOOKSTRUCT raton = (PMSLLHOOKSTRUCT)lParam;
 
   system("CLS");
   printf("X:%i\tY:%i\n",raton->pt.x, raton->pt.y);
 
   return CallNextHookEx(NULL, nCode, wParam, lParam);
}
 
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HHOOK MouseHook = SetWindowsHookEx(WH_MOUSE_LL,LowLevelMouseProc,hInstance,0);
 
   MessageBoxA(0,"Si pulsas aceptar acabará el programa",0,0);
   return 0;
}
 

Pueden dar su opinión si piensan que hay una manera mas óptima de hacerlo.

saludos.


Si quieres inutilizar el raton:

Código
LRESULT CALLBACK LowLevelMouseProc(int    nCode, WPARAM wParam, LPARAM lParam)
{
   PMSLLHOOKSTRUCT raton = (PMSLLHOOKSTRUCT)lParam;
 
   if (raton->pt.x != 0 || raton->pt.y != 0);
   {
       SetCursorPos(0,0);
   }
 
   return CallNextHookEx(NULL, nCode, wParam, lParam);
}

crack81:
Hola fary que ventaja tiene usar esta hook frente a la función GetCursorPos

Salutos...

fary:
Cita de: crack81 en  4 Abril 2016, 18:37 pm

Hola fary que ventaja tiene usar esta hook frente a la función GetCursorPos

Salutos...


Para usar GetCursosPos necesitas un bucle que consumirá muchísima más memoria.

Con este hook funcionará como si fuese un evento, es decir solo se activará cuando sea necesario.

crack81:
Vale gracias por la info  fary cuando ande en windows lo pruebo

Salutos...

79137913:
HOLA!!!

Aunque el Hook muchas veces saltara por heuristica, si se tienen recursos esta buena la idea de ejecutar on the fly el codigo con get cursor pos y que dumpee un log a algun sitio, asi es mas  facil evitar deteccion.

GRACIAS POR LEER!!!

Navegación

[0] Índice de Mensajes

[#] Página Siguiente