Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages
Started by Tom
Mon, 10 Apr 2006 19:31
Disable keyboard only
Author: Tom
Date: Mon, 10 Apr 2006 19:31
Date: Mon, 10 Apr 2006 19:31
3 lines
995 bytes
995 bytes
I need to disable keyboard (including ctr+alt+del, ctrl+shift+esc,...), but I need to leave the mouse enabled. Is there anything similar to BlockInput(True), but for keyboard only.
Re: Disable keyboard only
Author: Remy Lebeau (TeamB)
Date: Mon, 10 Apr 2006 21:19
Date: Mon, 10 Apr 2006 21:19
13 lines
1317 bytes
1317 bytes
"Tom" <tom@net.com> wrote in message news:443ab295$1@newsgroups.borland.com... > I need to disable keyboard (including ctr+alt+del, ctrl+shift+esc,...), > but I need to leave the mouse enabled. Is there anything similar to > BlockInput(True), but for keyboard only. You will have to install a global keyboard hook via the SetWindowsHookEx() function in a DLL, and have your callback function discard all key strokes. Gambit
Re: Disable keyboard only
Author: Tom
Date: Tue, 11 Apr 2006 06:43
Date: Tue, 11 Apr 2006 06:43
48 lines
2255 bytes
2255 bytes
My Form code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
FARPROC HookProc;
HINSTANCE DLL;
HHOOK Hook;
DLL = LoadLibrary("DLL.dll");
HookProc = GetProcAddress(DLL, "KeyboardHookProc");
Hook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)HookProc, DLL, NULL);
}
//---------------------------------------------------------------
MY Dll code:
#include <windows.h>
LRESULT CALLBACK KeyboardHookProc(int code, WPARAM wParam, LPARAM lParam)
{
return CallNextHookEx(NULL, code, wParam, lParam);
}
//---------------------------------------------------------------
Is this SetWindowsHookEx() ok, should I simply remove return 0 instead of
CallNextHookEx(NULL, code, wParam, lParam) from dll?
Thanks in advance,
Tom.
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:443acbd9$1@newsgroups.borland.com...
>
> "Tom" <tom@net.com> wrote in message
> news:443ab295$1@newsgroups.borland.com...
>
> > I need to disable keyboard (including ctr+alt+del, ctrl+shift+esc,...),
> > but I need to leave the mouse enabled. Is there anything similar to
> > BlockInput(True), but for keyboard only.
>
> You will have to install a global keyboard hook via the SetWindowsHookEx()
> function in a DLL, and have your callback function discard all key
strokes.
>
>
> Gambit
>
>
Re: Disable keyboard only
Author: Remy Lebeau (TeamB)
Date: Tue, 11 Apr 2006 07:32
Date: Tue, 11 Apr 2006 07:32
35 lines
2035 bytes
2035 bytes
"Tom" <tom@net.com> wrote in message news:443b501d@newsgroups.borland.com...
> My Form code:
You should call SetWindowsHookEx() from inside the DLL's code, not the EXE's
code. Have the DLL export two extra functions that the EXE can call to
set/remove the hook.
> MY Dll code:
You did not show your export statements. Are you exporting the hook
function at all?
> Is this SetWindowsHookEx() ok
It does absolutely nothing to accomplish what you were originally asking
for. You are not doing anything with the keystrokes, and you are not
discarding them.
> should I simply remove return 0 instead of
> CallNextHookEx(NULL, code, wParam, lParam) from dll?
Did you read the documentation yet?
"To prevent Windows 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."
Please go to http://www.deja.com and do a search through the newsgroup
archives. Sample code for using global hooks has been posted many times
before.
Gambit
Re: Disable keyboard only
Author: Tom
Date: Tue, 11 Apr 2006 07:51
Date: Tue, 11 Apr 2006 07:51
47 lines
2302 bytes
2302 bytes
sorry, I'll read the documentation before I continue with this issue. Thanks on your help. "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:443b5cbb$2@newsgroups.borland.com... > > "Tom" <tom@net.com> wrote in message news:443b501d@newsgroups.borland.com... > > > My Form code: > > You should call SetWindowsHookEx() from inside the DLL's code, not the EXE's > code. Have the DLL export two extra functions that the EXE can call to > set/remove the hook. > > > MY Dll code: > > You did not show your export statements. Are you exporting the hook > function at all? > > > Is this SetWindowsHookEx() ok > > It does absolutely nothing to accomplish what you were originally asking > for. You are not doing anything with the keystrokes, and you are not > discarding them. > > > should I simply remove return 0 instead of > > CallNextHookEx(NULL, code, wParam, lParam) from dll? > > Did you read the documentation yet? > > "To prevent Windows 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." > > Please go to http://www.deja.com and do a search through the newsgroup > archives. Sample code for using global hooks has been posted many times > before. > > > Gambit > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads