Discussion:
Determining Thread Id
(too old to reply)
tbannist
2005-04-26 20:08:06 UTC
Permalink
Ok, so I've got my keyboard hook code working except for one problem, it
currently hooks all keystrokes not just the ones destined for Word. It looks
like I need to determine the threadId for Word or the currently active
document window to create a local hook, however, I can't seem to find any
properties that will give me a threadId or even a window handle(wHnd) so I
can get the threadId.

Any suggestions on how to figure out what the thread id of Word is?
Jonathan West
2005-04-26 23:06:00 UTC
Permalink
You can get the Window handle by using the FindWindow or GetActiveWindow API
calls.

There are plenty of VB code samples on the web tat use one or other of these
API calls. A google search will find them. So long as the code is not
VB.NET, it should drop into a VBA project more or less unmodified.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Post by tbannist
Ok, so I've got my keyboard hook code working except for one problem, it
currently hooks all keystrokes not just the ones destined for Word. It looks
like I need to determine the threadId for Word or the currently active
document window to create a local hook, however, I can't seem to find any
properties that will give me a threadId or even a window handle(wHnd) so I
can get the threadId.
Any suggestions on how to figure out what the thread id of Word is?
tbannist
2005-04-28 15:58:14 UTC
Permalink
Post by Jonathan West
You can get the Window handle by using the FindWindow or GetActiveWindow
API calls.
Thanks, it turns out it wasn't the thread id that was the problem, for some
reason, I can't hook WH_KEYBOARD_LL on the Word thread, but I can hook
WH_KEYBOARD. Fortunately, WH_KEYBOARD is good enough for me.

Loading...