To implement a on-screen keyboard, all keyboard events need to be monitored regardless of whether the form is active or not. So you need a global hook, which is the system-wide hook.
What is a hook (hooks)
Hooks are a message processing mechanism platform provided by Windows, a function that is pre-initiated before receiving information in the normal running of a program is used to check and modify the information that is passed to the program (the hook) is actually a segment of the program that handles the message, and it is put into the system by the system call. Whenever a particular message is sent, the hook program captures the message before it reaches the destination window, which means that the hook function gets control first. The hook function can then process (change) the message, or it can continue to deliver the message without processing, and can force the end of the message to be passed. Note: Installing the hook function will affect the performance of the system. The system hooks for monitoring system-wide events are particularly noticeable. Because the system will call your hook function when it handles all related events, your system will obviously slow down. It should be used carefully and unloaded immediately after use. Also, because you can intercept messages from other processes in advance, it will affect other processes once your hook function is out of the question.
The scope of the hook
A total of two types of hooks, local and remote. Local hooks only hook up events of their own process. A remote hook can also hook up events that occur in other processes. There are two kinds of remote hooks: a thread-based hook captures events from a particular thread in another process. In short, it is an event that can be used to observe the occurrence of a particular thread in another process. A system-wide hook captures the event messages that will occur for all processes in the system.
Hook type
There are 14 types of hooks in Windows, and each type of hook enables an application to monitor different types of system message processing mechanisms. The following describes the timing of all available hook types. For more information on MSDN, here are just two types of hooks we'll be using.
(1) Wh_keyboard_ll Hook
The Wh_keyboard_ll hook monitors keyboard messages entered into thread message queues.