I have some useful code (incl declarations into user32) for checking
keyboard events but it needs Word's Window Handle (Word 2002) - Excel 2002
has Application.hWnd but there's nothing like that for Word alas.

Anyone know how to do this in VBA? (example would be apreciated)

Thanks

Julian

--
Julian I-Do-Stuff

Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com

Re: Get Word Window Handle? by Shauna

Shauna
Mon Jan 21 19:54:24 PST 2008

Hi Julian

At the top of the module, add the following:
Private Declare Function FindWindowByClass Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName
As Long) As Long


When you want the handle, use

Dim lngHWnd as long

lngHWnd = FindWindowByClass("opusapp", 0&)

FWIW, "Opus" was the code name for the first version of Word for
Windows.


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word



"Julian" <msforums@tiger2.demon.co.uk> wrote in message
news:uPwI3PFXIHA.5180@TK2MSFTNGP06.phx.gbl...
>I have some useful code (incl declarations into user32) for checking
>keyboard events but it needs Word's Window Handle (Word 2002) - Excel
>2002 has Application.hWnd but there's nothing like that for Word alas.
>
> Anyone know how to do this in VBA? (example would be apreciated)
>
> Thanks
>
> Julian
>
> --
> Julian I-Do-Stuff
>
> Some Vista stuff, but mostly just Stuff at
> http://berossus,blogspot.com



Re: Get Word Window Handle? by Julian

Julian
Tue Jan 22 00:43:24 PST 2008

Thanks Shauna - just what I was looking for!

I'd found something similar elsewhere but was missing the lpClassName,
which, as you demonstrated, was somewhat arbitrary (not like "XLMAIN")

Haven't tried it yet but it looks like it will do the trick perfectly - then
I will be able to do the auto-saving I want *only* when Word is idle...

VMT! Julian

--
Julian I-Do-Stuff

Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com
"Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in message
news:uxOPmrKXIHA.484@TK2MSFTNGP06.phx.gbl...
> Hi Julian
>
> At the top of the module, add the following:
> Private Declare Function FindWindowByClass Lib "user32" _
> Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
> Long) As Long
>
>
> When you want the handle, use
>
> Dim lngHWnd as long
>
> lngHWnd = FindWindowByClass("opusapp", 0&)
>
> FWIW, "Opus" was the code name for the first version of Word for Windows.
>
>
> Hope this helps.
>
> Shauna Kelly. Microsoft MVP.
> http://www.shaunakelly.com/word
>
>
>
> "Julian" <msforums@tiger2.demon.co.uk> wrote in message
> news:uPwI3PFXIHA.5180@TK2MSFTNGP06.phx.gbl...
>>I have some useful code (incl declarations into user32) for checking
>>keyboard events but it needs Word's Window Handle (Word 2002) - Excel 2002
>>has Application.hWnd but there's nothing like that for Word alas.
>>
>> Anyone know how to do this in VBA? (example would be apreciated)
>>
>> Thanks
>>
>> Julian
>>
>> --
>> Julian I-Do-Stuff
>>
>> Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com
>
>


Re: Get Word Window Handle? by Julian

Julian
Tue Jan 22 04:52:22 PST 2008

Hi Shauna

That works nicely, but I've just realised I may have been asking the wrong
question (it's certainly harder to debug with this approach!)

What I want to do is to trap keyboard events so that I can note the time of
the last keypress...

any suggestions?

--
Julian I-Do-Stuff

Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com
"Shauna Kelly" <ShaunaKelly@SendNoSpamToShaunaKelly.com> wrote in message
news:uxOPmrKXIHA.484@TK2MSFTNGP06.phx.gbl...
> Hi Julian
>
> At the top of the module, add the following:
> Private Declare Function FindWindowByClass Lib "user32" _
> Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
> Long) As Long
>
>
> When you want the handle, use
>
> Dim lngHWnd as long
>
> lngHWnd = FindWindowByClass("opusapp", 0&)
>
> FWIW, "Opus" was the code name for the first version of Word for Windows.
>
>
> Hope this helps.
>
> Shauna Kelly. Microsoft MVP.
> http://www.shaunakelly.com/word
>
>
>
> "Julian" <msforums@tiger2.demon.co.uk> wrote in message
> news:uPwI3PFXIHA.5180@TK2MSFTNGP06.phx.gbl...
>>I have some useful code (incl declarations into user32) for checking
>>keyboard events but it needs Word's Window Handle (Word 2002) - Excel 2002
>>has Application.hWnd but there's nothing like that for Word alas.
>>
>> Anyone know how to do this in VBA? (example would be apreciated)
>>
>> Thanks
>>
>> Julian
>>
>> --
>> Julian I-Do-Stuff
>>
>> Some Vista stuff, but mostly just Stuff at http://berossus,blogspot.com
>
>


Re: Get Word Window Handle? by Jonathan

Jonathan
Tue Jan 22 06:23:16 PST 2008


"Julian" <msforums@tiger2.demon.co.uk> wrote in message
news:eoyruWPXIHA.4140@TK2MSFTNGP04.phx.gbl...
> Hi Shauna
>
> That works nicely, but I've just realised I may have been asking the wrong
> question (it's certainly harder to debug with this approach!)
>
> What I want to do is to trap keyboard events so that I can note the time
> of the last keypress...
>
> any suggestions?

It sounds like you are trying to write a keylogger. Many such have already
been written, many of them open-source. Just do a web search for
"keylogger".


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup