Trapping Keystrokes from an Acrobat Plug-in on Windows

This is a question I get a lot – “How do I prevent certain hotkeys from being issued by the user using the Acrobat SDK?”. Well, quite frankly, the answer is – you don’t. The Acrobat SDK does not provide any mechanism for trapping keys in the Acrobat interface, and these features have been left out for a good reason; your platform APIs already have a mechanism to do this, and they provide much greater control than anything the SDK could provide (which would need to be limited in scope to the active application window). You can use these platform APIs in your plug-ins, using your plug-in as a proxy to these interfaces, and doing whatever you want with the resulting responses from the platform APIs.


In this article, we’re focusing on Windows (since this is the OS the majority or these questions come from). We’ll be focusing on the SetWindowsHookEx method to set up a keyboard hook that will pass all keystrokes to a callback, analyze the key codes and discard the ones that we want to ignore while passing the rest on down the line.

For the purposes of this article, I have modified the file “BasicPlugin.cpp”, which is part of the “BasicPlugin” sample contained in the Acrobat 9 SDK. I am using Visual Studio 2005, as this is the only tested & supported platform for developing Acrobat plug-ins on Windows.

You can download the updated “BasicPlugin.cpp” here. Simple replace the BasicPlugin.cpp in the PluginSupport/Samples/BasicPlugin/Sources folder and rebuild the project. This will add a menu item in Acrobat named “Hook Plugin” under the “Acrobat SDK” submenu. Choose this menu item and it will alternate enabling or disabling the hook. I have hooked CTRL+C, CTRL+V, CTRL+X in order to demonstrate impeding a user from using hotkeys to copy data from a PDF.