BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to hook the keyboard?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Non-Technical)
View previous topic :: View next topic  
Author Message
feicoremvethis@gmx.net
Guest





PostPosted: Wed Nov 19, 2003 1:03 pm    Post subject: How to hook the keyboard? Reply with quote



Dear friends

I want to write a program that intercepts keyboard input. I have tried
something with a program named SetWindowsHookEx. It compiles without requiring
a header, but it cannot be executed. I think I do not know what arguments to
use. The documentation is rather enigmatic.

Can anyone help me?


--
Feico
Back to top
Yu-Chen Hsueh
Guest





PostPosted: Wed Nov 19, 2003 4:28 pm    Post subject: Re: How to hook the keyboard? Reply with quote



Feico,

I sent you some demo code via private e-mail. Please post any replies here
rather than through private mail.

-- YH --


--
Any e-mail sent to me from the newsgroups will be ignored. Please confine
your posts to the newsgroups and DO NOT reply to this e-mail account.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Nov 19, 2003 5:47 pm    Post subject: Re: How to hook the keyboard? Reply with quote




<feicoremvethis (AT) gmx (DOT) net> wrote


Quote:
I want to write a program that intercepts keyboard input.

You are asking a technical question in a non-technical group. You should
post to the .nativeapi group instead.


Gambit



Back to top
feicoremvethis@gmx.net
Guest





PostPosted: Wed Nov 19, 2003 6:17 pm    Post subject: Re: How to hook the keyboard? Reply with quote

On Wed, 19 Nov 2003 09:47:31 -0800, "Remy Lebeau (TeamB)" <gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in
borland.public.cppbuilder.non-technical:

Quote:
You are asking a technical question in a non-technical group. You should
post to the .nativeapi group instead.

I tried that, but that group is not provided by my ISP.

--
Feico

Back to top
Ed Mulroy [TeamB]
Guest





PostPosted: Wed Nov 19, 2003 6:24 pm    Post subject: Re: How to hook the keyboard? Reply with quote

Quote:
I tried that, but that group is not provided by my ISP.

You are not accessing the groups correctly and will loose messages and
replies.

This is NOT a Usenet newsgroup. Your ISP grabs it for some unknown reason.
Tell your news reader to access the news server newsgroups.borland.com

.. Ed

Quote:
Feico wrote in message
news:4qcnrv0p9ngjrpdr9t1c38h26fi7j335g2 (AT) 4ax (DOT) com...

Remy Lebeau wrote:
You are asking a technical question in a non-technical group. You should
post to the .nativeapi group instead.

I tried that, but that group is not provided by my ISP.



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Nov 19, 2003 6:52 pm    Post subject: Re: How to hook the keyboard? Reply with quote


<feicoremvethis (AT) gmx (DOT) net> wrote


Quote:
I tried that, but that group is not provided by my ISP.

You should be accessing Borland's own newsserver directly:

forums.borland.com
or
newsgroups.borland.com

Do not use your ISP's server.


Gambit



Back to top
Feico
Guest





PostPosted: Wed Nov 19, 2003 7:08 pm    Post subject: Re: How to hook the keyboard? Reply with quote

On Wed, 19 Nov 2003 10:52:42 -0800, "Remy Lebeau (TeamB)"
<gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in borland.public.cppbuilder.non-technical:

Quote:
You should be accessing Borland's own newsserver directly:

forums.borland.com
or
newsgroups.borland.com

Do not use your ISP's server.

I see lots of newsgroups on http://info.borland.com/newsgroups/ng_cbuilder.html but many
of these appear not to be available, even if I select newsgroups.borland.com.

But I'll keep trying.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Nov 19, 2003 7:57 pm    Post subject: Re: How to hook the keyboard? Reply with quote


"Feico" <feicorem0veth1s (AT) gmx (DOT) net> wrote


Quote:
I see lots of newsgroups on
http://info.borland.com/newsgroups/ng_cbuilder.html
but many of these appear not to be available, even if I select
newsgroups.borland.com.


I can assure you that they are available on Borland's server. If you have
not done so, do a full refresh of the server's newsgroup listing.


Gambit



Back to top
Feico
Guest





PostPosted: Wed Nov 19, 2003 9:25 pm    Post subject: Re: How to hook the keyboard? Reply with quote

On Wed, 19 Nov 2003 11:57:59 -0800, "Remy Lebeau (TeamB)"
<gambit47.no.spam (AT) no (DOT) spam.yahoo.com> wrote in borland.public.cppbuilder.non-technical:

Quote:
I can assure you that they are available on Borland's server. If you have
not done so, do a full refresh of the server's newsgroup listing.

Yes, I found it now. I don't understand why it wasn't there initially. So let's continue
the thread there.


Back to top
Feico
Guest





PostPosted: Wed Nov 19, 2003 9:34 pm    Post subject: Re: How to hook the keyboard? Reply with quote

On Wed, 19 Nov 2003 08:28:37 -0800, "Yu-Chen Hsueh" <ychsueh (AT) borland (DOT) com> wrote in
borland.public.cppbuilder.non-technical:

Quote:
I sent you some demo code via private e-mail. Please post any replies here
rather than through private mail.

Thanks, this is really helpful. A function is hooked by calling
SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)LowLevelKeyboardProc, hInstance, 0);

The biggest problem is the value of hInstance, I think, which appears only to be available
in a DLL, not in an EXE. This problem is now solved.

However, I still find some funny behaviour.

The function LowLevelKeyboardProc executes this:

if(key must be disabled)
return 1;
else
CallNextHookEx (hKeyboardHook, nCode, wParam, lParam);

Actually it appears to disable every key, until I remove the hook.

Of course I wondered what happened, so I put a MessageBox in the function. Well, this
MessageBox is displayed twice whenever a key is hit. Even more surprising: no more keys
are disabled when the MessageBox is included.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Nov 19, 2003 9:49 pm    Post subject: Re: How to hook the keyboard? Reply with quote

"Feico" <feicorem0veth1s (AT) gmx (DOT) net> wrote


Quote:
The biggest problem is the value of hInstance, I think, which appears
only to be available in a DLL, not in an EXE.

Not true. You can use the global HInstance variable for an EXE, which is
obtained from the startup code that triggers WinMain().

However, if you're calling SetWindowsHookEx() from inside the EXE itself,
then chances are you're only going to be hooking just that EXE to begin
with, not all running EXEs, so you could set the hInstance parameter to
NULL.

Quote:
Actually it appears to disable every key, until I remove the hook.

How exactly are you determine that keys need to be disabled? I would guess
a bug in that logic is returning 'true' for every key, rather than just the
keys you're actually interested in.


Gambit



Back to top
Feico
Guest





PostPosted: Thu Nov 20, 2003 7:56 am    Post subject: Re: How to hook the keyboard? Reply with quote

On Wed, 19 Nov 2003 08:28:37 -0800, "Yu-Chen Hsueh" <ychsueh (AT) borland (DOT) com> wrote in
borland.public.cppbuilder.non-technical:

Quote:
I sent you some demo code via private e-mail. Please post any replies here
rather than through private mail.

Thanks Yu, that was very helpful, although the statement
if (pkbhs->vkCode == VK_LWIN || VK_RWIN)
caused me some trouble.

Back to top
Yu-Chen Hsueh
Guest





PostPosted: Thu Nov 20, 2003 5:55 pm    Post subject: Re: How to hook the keyboard? Reply with quote

Feico,

Sorry about that. I wrote it some time ago, and honestly don't remember all
the details. It wasn't for production, mainly just for fun, so some of the
logic could definitely be flakey. Hopefully it helped you get headed on the
right path, though.

Take care,

-- YH --


--
Any e-mail sent to me from the newsgroups will be ignored. Please confine
your posts to the newsgroups and DO NOT reply to this e-mail account.


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Nov 20, 2003 6:14 pm    Post subject: Re: How to hook the keyboard? Reply with quote


"Feico" <feicorem0veth1s (AT) gmx (DOT) net> wrote


Quote:
Thanks Yu, that was very helpful, although the statement
if (pkbhs->vkCode == VK_LWIN || VK_RWIN)
caused me some trouble.

That is not a valid statement. Well, it is, but it does not do what you
think it does. You have to test each condition individually instead:

if( (pkbhs->vkCode == VK_LWIN) || (pkbhs->vkCode == VK_RWIN) )


Gambit



Back to top
Saulo I. Regis
Guest





PostPosted: Fri Nov 21, 2003 10:46 am    Post subject: Re: How to hook the keyboard? Reply with quote

Hi Yu-Chen,

I would appreciate if you could send this demo also to me.

TIA

Saulo


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Non-Technical) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.