|
-
April 16th, 1999, 03:32 AM
#3
Re: Hotkey?
Hi
I was under the impression that you couldn't actually create a system -
wide keyboard hook in VB. As I understand it, a VB Exe can only trap
keyboard events in it's own process space.
If you want to create a Keyboard hook, you'll need to use C/C++/Delphi or
some other tool that can create DLL's. This DLL can then do a SendMessage
to your VB application which you can capture with a subclassing routine.
eg:
#include "windows.h"
#include "keyhook.h"
#include "winuser.h"
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam);
HANDLE hInstance =0;
HHOOK hhookKeyb =0;
MSG Msg;
BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD dwReason, LPVOID reserved)
{
hInstance = hinstDll;
return TRUE;
}
LRESULT CALLBACK KeyboardFunc (int nCode, WPARAM wParam, LPARAM lParam)
{
LRESULT ret;
/* Here we are in the Keyboard - Hook */
if (nCode < 0)
return (CallNextHookEx(hhookKeyb, nCode, wParam, lParam));
else
{
ret = CallNextHookEx(hhookKeyb, nCode, wParam, lParam);
if (wParam == 110) /* Which vKey is it??*/
/* Now do something (maybe post a message or so */
return 1;
}
else
return ret;
}
}
void InitKeyWatch (BOOL install)
{
if (install)
{
hhookKeyb = SetWindowsHookEx (WH_KEYBOARD, (HOOKPROC)KeyboardFunc, hInstance, 0);
}
else
{
UnhookWindowsHookEx(hhookKeyb);
}
}
Regards
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|