[New for Windows NT 4.0 Service Pack 3.]
The LowLevelKeyboardProc hook procedure is an application-defined or library-defined callback function the system calls every time a new keyboard input event is about to be posted into a thread input queue. The system calls this hook before the event is processed.
The keyboard input can come from the local keyboard driver or from calls to the keybd_event function. If the input comes from a call to keybd_event, the input was “injected”.
LRESULT CALLBACK LowLevelKeyboardProc(
int nCode, |
// hook code |
WPARAM wParam, |
// message identifier |
LPARAM lParam |
// pointer to structure with message data |
); |
Value |
Meaning |
HC_ACTION |
The wParam and lParam parameters contain information about a keyboard message. |
If nCode is less than zero, the hook procedure must pass the message to
the CallNextHookEx function without
further processing and should return the value returned by CallNextHookEx.
To prevent the system from passing the message to the rest of the hook chain or to the target window procedure, the return value must be a nonzero value. To allow the system to pass the message to the target window procedure, bypassing the remaining procedures in the chain, the return value must be zero.
An application installs the hook procedure by specifying the WH_KEYBOARD_LL hook type and the address of the hook procedure in a call to the SetWindowsHookEx function.
This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.
The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout value in the following registry key:
HKEY_CURRENT_USER\Control Panel\Desktop
The value is in milliseconds. If the hook procedure does not return during this interval, the system will pass the message to the next hook.
Note that debug hooks cannot track this type of hook.
CallNextHookEx, KBDLLHOOKSTRUCT, keybd_event, SetWindowsHookEx, WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
Questions:
I am writing an application in java. In my application i would prevent users to do the alt-tab.+
For that, i wrote the dll (HelloWorld.cpp) below :
//the callback function
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
PKBDLLHOOKSTRUCT p;
// to verify that the function has been called
char ch;
FILE* f1=fopen("C:\eclipse\workspace\native\report.txt","a+");
ch='\n';
fwrite(&ch,1,1,f1);
fclose(f1);
// to diable the Alt-Tab
if (nCode == HC_ACTION)
{
p = (PKBDLLHOOKSTRUCT) lParam;
if (
// ALT+TAB
(p->vkCode == VK_TAB && p->flags & LLKHF_ALTDOWN)
)
return 1;
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}
/*****************************************************
* to install the hook
* Enable/Disable task switching keys. *
* (Alt+Tab) *
* TRUE=Enable, FALSE=Disable *
* (Win NT4SP3+, Win2K). *
*****************************************************/
JNIEXPORT jboolean JNICALL Java_HelloWorld_installhook
(JNIEnv *, jclass, jboolean bEnableDisable)
{
if (!bEnableDisable)
{
// Install the low-level keyboard hook
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
(HOOKPROC)LowLevelKeyboardProc,
(HINSTANCE)NULL,
GetCurrentThreadId());
if (!hKeyboardHook)
return 0;
}
else
{
UnhookWindowsHookEx(hKeyboardHook);
hKeyboardHook = NULL;
}
return 1;
}
but when i call the installhook from my java application it return a false value(0),means that the hook is not installed.
the method installhook is called from :
public class HelloWorld {
static { System.loadLibrary("HelloWorld"); }
public static native boolean installhook(boolean bEnableDisable);
public static void main(String args[]) {
System.out.print("Hello ");
boolean bool = HelloWorld.installhook(false);
System.out.print("bool : " + bool);
}
Could you please help me ?
Thanks for you
Kass29
Comments:
http://www.velocityreviews.com/forums/t360927-setwindowshookex-not-notifing-me-on-key-pressed-using-jni-and-c-dll.html pass HINSTANCE handle of dll to SetWindowsHookEx() and 0 for thread id this will work.+
g_hHookKbdLL = SetWindowsHookEx(WH_KEYBOARD_LL,MyTaskKeyHookLL, m_hmodule, 0);
file: /Techref/os/win/api/win32/func/src/f55_10.htm, 8KB, , updated: 2009/12/24 11:46, local time: 2024/11/30 20:14,
18.220.242.160:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://techref.massmind.org/techref/os/win/api/win32/func/src/f55_10.htm"> LowLevelKeyboardProc</A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to techref.massmind.org! |
.