B
bourgui
Hi all,
I set up a local keyboard hook in powerpoint (so that I can define my
own shortcuts), using SetWindowsHookEx etc....
The hook works fine, but I get this strange problem: if my
'KeyHandler' (the callback procedure for my hook) function calls
another routine that itself makes a 'GetObject' call, the 'KeyHandler'
seems to reset the keyevent, as I receive the event again through the
callback procedure.
For example, lets imagine that on a KeyDown event, I call the
'CreateShape' routine, defined as follows:
I set up a local keyboard hook in powerpoint (so that I can define my
own shortcuts), using SetWindowsHookEx etc....
The hook works fine, but I get this strange problem: if my
'KeyHandler' (the callback procedure for my hook) function calls
another routine that itself makes a 'GetObject' call, the 'KeyHandler'
seems to reset the keyevent, as I receive the event again through the
callback procedure.
For example, lets imagine that on a KeyDown event, I call the
'CreateShape' routine, defined as follows:
Code:
Sub CreateShape()
Dim mObj As Object
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeRectangle,
Rnd * 250, Rnd * 100, Rnd * 300, Rnd * 175).Select
On Error GoTo NotRunning
Set mObj = GetObject(, "Word.Application")
Exit Sub
NotRunning:
MsgBox "Word not running"
End Sub
[CODE]
(I realize the 'GetObject' call is completely useless here, but this
is just to illustrate what happens. Also, I used Word in the exemple,
but the same thing happens with all other applications I have tried)
If Word happens to be running, anywhere from 5 to 20 shapes will be
created, as the KeyHandler is called several times, suggesting that
the keyEvent is being fed back somehow. Sometimes VBA crashes, I
supposed caught in an infinite loop.
If Word is not running, the message box will popup as expected, but
twice in a row.
The time seems to be a factor in this case as, if step through
manually, the problem doesn't usually happen.
I don't have any problems with any of my functions when they get
called by any other mean than the callback procedure, and this code
has been in use for a while now, so the problem must come the hook.
Does anybody have any idea how I can ensure that the callback
procedure will wait for the proper execution of GetObject?
Or is it something else?
Thanks!