Keyboard hook...

Hi,

this function is called:

void SetKBHook(void)
{
KH1 = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KHookProc,hInst,0L);
}

KH1 is 0, why? :(
-hInst is my app instance
-KHookProc is the correct HookProc

hhheelllppp...

cu,

illuminator
(Novus ordo seclorum)

Comments

  • What OS? WH_KEYBOARD_LL does not work in 9x.

    Also, is this in an EXE or DLL? Because passing an hInstance should be done only with system-wide hooks that reside in a DLL. For a local hook in an EXE use:
    KH1 = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)KHookProc, NULL, GetCurrentThreadId());

    Which hooks the keyboard for the current process only.

    : Hi,
    :
    : this function is called:
    :
    : void SetKBHook(void)
    : {
    : KH1 = SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)KHookProc,hInst,0L);
    : }
    :
    : KH1 is 0, why? :(
    : -hInst is my app instance
    : -KHookProc is the correct HookProc
    :
    : hhheelllppp...
    :
    : cu,
    :
    : illuminator
    : (Novus ordo seclorum)
    :

  • Thx !! :)

    cu,

    illuminator
    (Novus ordo seclorum)

  • Hi

    1. Thx. Your code works. :)

    2. Hm, i tried to convert it to VB.NET, works also, but this structure causes huge problems:

    C:
    typedef struct tagKBDLLHOOKSTRUCT {
    DWORD vkCode;
    DWORD scanCode;
    DWORD flags;
    DWORD time;
    DWORD dwExtraInfo;
    } KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;

    VB.Net:
    Public Structure KBDLLHOOKSTRUCT
    Public vkCode As Integer
    Public scanCode As Integer
    Public flags As Integer
    Public time As Integer
    Public dwExtraInfo As Integer
    End Structure
    - Wrong :( Why?

    PS: you guys are great! ;)



    cu,

    illuminator
    (Novus ordo seclorum)

  • [b][red]This message was edited by pingpong at 2003-1-20 11:43:29[/red][/b][hr]
    /edit Yikes, got my VB mixed up with C#. Why dont you use C# by the way?

    You need the StructLayout attribute thingy..
    [code]
    Imports System.Runtime.InteropServices

    _
    Public Structure KBDLLHOOKSTRUCT
    Public vkCode As Integer
    Public scanCode As Integer
    Public flags As Integer
    Public time As Integer
    Public dwExtraInfo As Integer
    End Structure
    [/code]
    So .NET wont mess around with it and tries to optimize it. The pack=1 is standard Win32 API stuff.

    Dont know how are you going to make the LowLevelKeyboardProc work though, this might work:
    [code]
    _
    Public Shared Function LowLevelKeyboardProc(nCode As Integer, wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) As Integer
    [/code]
    If it doesnt, it means that Windows is trying to send a NULL in the lParam, dont know how you fix that in VB.NET, in C# you can declare it as int lParam then do the appropriate cast in a fixed block.

    Good luck.

    : Hi
    :
    : 1. Thx. Your code works. :)
    :
    : 2. Hm, i tried to convert it to VB.NET, works also, but this structure causes huge problems:
    :
    : C:
    : typedef struct tagKBDLLHOOKSTRUCT {
    : DWORD vkCode;
    : DWORD scanCode;
    : DWORD flags;
    : DWORD time;
    : DWORD dwExtraInfo;
    : } KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;
    :
    : VB.Net:
    : Public Structure KBDLLHOOKSTRUCT
    : Public vkCode As Integer
    : Public scanCode As Integer
    : Public flags As Integer
    : Public time As Integer
    : Public dwExtraInfo As Integer
    : End Structure
    : - Wrong :( Why?
    :
    : PS: you guys are great! ;)
    :
    :
    :
    : cu,
    :
    : illuminator
    : (Novus ordo seclorum)
    :
    :



  • Hi

    thx again! :)

    _
    Public Structure KBDLLHOOKSTRUCT
    Public vkCode As Integer
    Public scanCode As Integer
    Public flags As Integer
    Public time As Integer
    Public dwExtraInfo As Integer
    End Structure

    "Pack = 1" was not accepted, because "StructLayout" only expects one parameter.

    cu,

    illuminator
    (Novus ordo seclorum)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories