Article View: borland.public.cppbuilder.nativeapi
Article #14541SetWindowsHookEx & WH_KEYBOARD
From: MWP
Date: Mon, 11 Aug 2003 07:41
Date: Mon, 11 Aug 2003 07:41
53 lines
2433 bytes
2433 bytes
Hi all...
I have made a DLL that uses SetWindowsHookEx(WH_KEYBOARD....) to get keypreesses.
The problem is its not global... it only works while the app using the DLL is in focus.
How do i fix this?
Code for the DLL is below.
Thanks.
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#define EXTC extern "C"
#define DLLOPT __export WINAPI
HHOOK hhook;
HINSTANCE hinste;
DWORD lastkey;
DWORD lastlp;
//---------------------------------------------------------------------------
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
hinste = hinst;
return 1;
}
//---------------------------------------------------------------------------
LRESULT KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
lastkey = wParam;
lastlp = lParam;
return CallNextHookEx(hhook, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
EXTC void DLLOPT install_hook()
{
hhook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)KeyboardProc, hinste, 0);
}
//---------------------------------------------------------------------------
EXTC void DLLOPT last_key(DWORD *key, DWORD *lp)
{
*key = lastkey;
*lp = lastlp;
}
//---------------------------------------------------------------------------
Technical Details
Message-ID:
<3f374896@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,65d385623513ec23,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-11 01:12:01 PST From: "MWP" <mwp@overclockers.com.au> Sender: "MWP" <mwp@overclockers.com.au> Reply-To: "MWP" <mwp@overclockers.com.au> Subject: SetWindowsHookEx & WH_KEYBOARD Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 203.16.214.242 203.16.214.242 X-Forwarded-For: unknown, 150.101.76.105 NNTP-Posting-Host: 207.105.83.65 Message-ID: <3f374896@newsgroups.borland.com> Date: 11 Aug 2003 00:41:10 -0700 X-Trace: newsgroups.borland.com 1060587670 207.105.83.65 (11 Aug 2003 00:41:10 -0700) Lines: 56 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail