Using hooks (hook) to achieve C # Screen Keyboard effect

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.