Closed JBB2020 closed 3 years ago
Hi there. I'm really sorry for not seeing this earlier. It's been a while since I worked on my personal projects.
The hook is supposed to be called before anything else, so it's hard to tell what the issue may be (perhaps you're not binding it to the correct thread?). I will test this to see if I can recreate the issue, but it would be really helpful if you could share the code you use to set up the hook.
I have tried this out with a basic keyboard hook in PowerPoint (Office 365) and I cannot reproduce the issue. The keystroke is blocked as it's supposed to.
Please construct a small code example that reproduces the issue and attach it here. Also let me know which version of PowerPoint you are using.
My working example:
Public Class ThisAddIn
Dim WithEvents KeyboardHook As InputHelper.Hooks.LocalKeyboardHook
Private Sub ThisAddIn_Startup() Handles Me.Startup
KeyboardHook = New InputHelper.Hooks.LocalKeyboardHook()
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
KeyboardHook.Dispose()
End Sub
Private Sub KeyboardHook_KeyDown(sender As Object, e As KeyboardHookEventArgs) Handles KeyboardHook.KeyDown
If e.Modifiers = (InputHelper.ModifierKeys.Control Or InputHelper.ModifierKeys.Shift) AndAlso e.KeyCode = Windows.Forms.Keys.C Then
e.Block = True
End If
End Sub
End Class
Good evening Vincent,
Thanks for taking time to investigate the issue!
I found out what was not working. I would call my custom actions before the e.block = true instruction. This would result in PowerPoint handling the input as usual before my custom instruction was executed.
I am now starting with the e.block instruction immediatly at the begining of the if block. And it now does what I want it to 🙂
Thanks again for your help,
JB
Jean-Baptiste Boucher +33.6.36.44.38.10
De : Visual Vincent notifications@github.com Envoyé : jeudi 25 février 2021 10:48 À : Visual-Vincent/InputHelper InputHelper@noreply.github.com Cc : JBB2020 jb.boucher@outlook.com; Author author@noreply.github.com Objet : Re: [Visual-Vincent/InputHelper] Key capture occurs after PowerPoint dealt with the keystrokes (#4)
I have tried this out with a basic keyboard hook in PowerPoint (Office 365) and I cannot reproduce the issue. The keystroke is blocked as it's supposed to.
Please construct a small code example that reproduces the issue and attach it here. Also let me know which version of PowerPoint you are using.
My working example:
Public Class ThisAddIn
Dim WithEvents KeyboardHook As InputHelper.Hooks.LocalKeyboardHook
Private Sub ThisAddIn_Startup() Handles Me.Startup
KeyboardHook = New InputHelper.Hooks.LocalKeyboardHook()
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
KeyboardHook.Dispose()
End Sub
Private Sub KeyboardHook_KeyDown(sender As Object, e As KeyboardHookEventArgs) Handles KeyboardHook.KeyDown
If e.Modifiers = (InputHelper.ModifierKeys.Control Or InputHelper.ModifierKeys.Shift) AndAlso e.KeyCode = Windows.Forms.Keys.C Then
e.Block = True
End If
End Sub
End Class
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FVisual-Vincent%2FInputHelper%2Fissues%2F4%23issuecomment-785765196&data=04%7C01%7C%7C110f66520be9445aa81408d8d9727e67%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637498433054271529%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=drPLSO2fFJWX%2Fa9YZHpB%2FMcZixU0Q2ALmH7uqB08%2FfY%3D&reserved=0, or unsubscribehttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FARYKZUGSKSOPHHEEBGJ7RL3TAYMGPANCNFSM4TWET6RQ&data=04%7C01%7C%7C110f66520be9445aa81408d8d9727e67%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637498433054281491%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=8C4koG1i2AwVfGdayWM629OM9JtuUb5uohxe181To%2F8%3D&reserved=0.
Weird... Unless your custom actions take a long time (a couple of 100 ms), the position of e.Block = True
shouldn't matter as it isn't checked until all event handlers have executed completely.
Anyway, glad your issue is solved!
Is there a way to have the hook called before that PowerPoint receives the event? The goal here would be to use your (great) library to create custom keyboard shortcuts from a VSTO addin. However, currently, when using a
LocalKeyboardHook
to capture the event CTRL + SHIFT + C, for instance, then PowerPoint's standard feature for "copy format" still occur before my addin deal (and tries to block) the event.