Capture Keydown event from Word document in VB
I actually want to capture the keydown or keypress event from the active word document from my VB6 application.
I know of some events.
Dim WithEvents AppWord As Word.Application
set AppWord = CreateObject("Word.Application")
AppWord.Documents.Add AppMap & "Blanc.doc"
....
Private Sub AppWord_Documentchange()
msgbox "changed to other document"
end sub
There is allso an open and close/quit document event.
but i don't know about a keydown event. Can someone help.
The documenychange would allso be good if this means when the user changes the active document by typing in it, but here it sadly means just switching from one doc to another
If there is no keydown event for this maybe i should try something else
Like capturing the pressed key with a API call like keyboardstate (allready tried this but didn't work because me VB6 form didn't had the focus while typing in de word doc)
Checking a textbox keydown event from the active document would allso be good if possible from my VB. But this seems more difficult. Allso i create the textboxes at run time not at design time
And it's not een array of textboxes (didn't know how to do that). I create textboxes like TKVeld1026 and the next one gets name TKVeld1027 or is there a better way.
Does anyone know a solution, i got stuck here?
Re: Capture Keydown event from Word document in VB
Moved to Office Development.
Re: Capture Keydown event from Word document in VB
There is no DocumentChanged event. Only Open, Close, and New are the relevant events. You may have to, if the doc is saved already, compare the saved content to the current content.
Re: Capture Keydown event from Word document in VB
Thx for reply
Good to know there is no DocumentChanged event. An other way has to be taken.
You mention checking the saved document with the current,
but i need it to trigger as soon as the user pushes a key! :sick: I cannot constantly save the doc.
Allso checking the document in memory, and comparing it a second later for changes, seems strange to do and very slow, and u need a timer...
Maybe i do need to capture a document keydown event somehow, and this through my VB6 application.....
Please some help, i got stuck here
Re: Capture Keydown event from Word document in VB
You may have to do some keyboard hooking involving APIs to get any keypresses. Its not really my area of expertise but could be worth a try or maybe someone has another suggestion
Re: Capture Keydown event from Word document in VB
Probably this is the way to go.
I already tried GetKeyboardState api ,
that I put in a timer
But when the focus leaves the form and is in the Word doc, it doesn't catch the keys anymore :(
I'ts a pity because this normally allso catches mouseclick events and i allso need those !
If there is a more powerfull api, please let me know.
By the way the api should work on all windows systems from Win98 er higher.