low level system hook

16/01/2004 - 17:00 por sergi | Informe spam
hola,

necesito recoger los eventos de tecla en mi aplicación, aunque esta no esté
activa, he tratado de pasar un ejemplo de system windows hooks que vi en vb
.net a c# , pero no me responde igual, no sé qué es lo que estoy haciendo
mal, os agradeceria me dierais una solución ;)

<codigo>
using System;

using System.Runtime.InteropServices;

namespace IOHTV

{

[ StructLayout( LayoutKind.Sequential)]

public struct KBDLLHOOKSTRUCT

{


int vkCode;

int scanCode;

int flags;

int time;

int dwExtraInfo;

}

public class KeyBoardHooksManager

{

public delegate int LowLevelKeyBoardProcDelegate(int nCode, int wParam, ref
KBDLLHOOKSTRUCT lParam);

[DllImport("user32.dll")]

public static extern int SetWindowsHookExA(int idHook,
LowLevelKeyBoardProcDelegate lpfn, int hMod, int dwThreadId);

[DllImport("user32.dll")]

public static extern int UnhookWindowsHookEx(int hHook);

[DllImport("user32.dll")]

public static extern int CallNextHookEx(int hHook, int nCode, int wParam,
ref KBDLLHOOKSTRUCT lParam);


public static int LowLevelKeyBoardProc(int nCode, int wParam, ref
KBDLLHOOKSTRUCT lParam)

{

Console.WriteLine("Key event");


return 1;

}

public const int WH_KEYBOARD_LL = 13;


public void Test()

{

KeyBoardHooksManager.SetWindowsHookExA(WH_KEYBOARD_LL, new
LowLevelKeyBoardProcDelegate(LowLevelKeyBoardProc) ,
Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetMo
dules()[0]).ToInt32(), 0);

}

}


class Class1

{

[STAThread]

static void Main(string[] args)

{

KeyBoardHooksManager a = new KeyBoardHooksManager();

a.Test();

Console.Read();

}

}

}

</codigo>
 

Leer las respuestas

#1 Anonimo
21/01/2004 - 19:20 | Informe spam
sergio:

por lo que se ve estás queriendo setear un hook global y
eso no puede hacerse directamente con .NET.

mirá el siguiente artículo..

http://support.microsoft.com/defaul...cid=kb;EN-
US;318804

salu2!!

pablo


Mostrar la cita
aunque esta no esté
Mostrar la cita
hooks que vi en vb
Mostrar la cita
que estoy haciendo
Mostrar la cita
nCode, int wParam, ref
Mostrar la cita
dwThreadId);
Mostrar la cita
nCode, int wParam,
Mostrar la cita
wParam, ref
Mostrar la cita
(System.Reflection.Assembly.GetExecutingAssembly().GetMo
Mostrar la cita

Preguntas similares