C # Screen Keyboard (soft keyboard screenkeyboard)

Source: Internet
Author: User
To implement a screen keyboard, you need to listen to all Keyboard Events, whether or not the form is activated. Therefore, a global hook is required, that is, the system range hook.

What is hook)

Hook is a message processing platform provided by windows. It is a function started in advance before the program receives information during normal operation. It is used to check and modify Information transmitted to the program, A hook is actually a program segment for message processing. It is called by the system and mounted to the system. When a specific message is sent, the hook program captures the message before it reaches the target window, that is, the hook function gets control of the message first. In this case, the hook function can process (Change) the message, continue to transmit the message without processing it, and forcibly end the message transmission. Note: Installing the hook function will affect the system performance. The system hooks for monitoring "system-scope events" are particularly obvious. Because the system calls your hook function when processing all related events, your system will obviously slow down. Therefore, use it with caution and uninstall it immediately after use. In addition, because you can intercept messages from other processes in advance, once your hook function has a problem, it will certainly affect other processes.

Hook Scope

There are two types of hooks, local and remote. Local hooks only hook events of your own processes. Remote hooks can also hook events that occur in other processes. There are two remote hooks: thread-based hooks capture events of a specific thread in other processes. In short, it can be used to observe the events that will happen to a specific thread in other processes. System-wide hooks capture the event messages that will occur by all processes in the system.

Hook type

There are 14 types of hooks in windows. Each type of hook enables applications to monitor different types of system message processing mechanisms. The following describes the occurrence time of all available hook types. For details, refer to msdn. Here we will only introduce the two types of hooks we will use.
(1) wh_keyboard_ll hook
Wh_keyboard_ll hook monitors keyboard messages that are input to the thread message queue.
(2) wh_mouse_ll hook
Wh_mouse_ll hook monitors the mouse messages that are input to the thread message queue.

After the hook is used, uninstall it. This can be written in the destructor.

Below is the virtual key code table corresponding to the buttons on the keyboard:

Vk_f1 = 0x70;
Vk_f2 = 0x71;
Vk_f3 = 0x72;
Vk_f4 = 0x73;
Vk_f5 = 0x74;
Vk_f6 = 0x75;
Vk_f7 = 0x76;
Vk_f8 = 0x77;
Vk_f9 = 0x78;
Vk_f10 = 0x79;
Vk_f11 = 0x7a;
Vk_f12 = 0x7b;

Vk_left = 0x25;
Vk_up = 0x26;
Vk_right = 0x27;
Vk_down = 0x28;

Vk_none = 0x00;
Vk_escape = 0x1b;
Vk_execute = 0x2b;
Vk_cancel = 0x03;
Vk_return = 0x0d;
Vk_accept = 0x1e;
Vk_back = 0x08;
Vk_tab = 0x09;
Vk_delete = 0x2e;
Vk_capital = 0x14;
Vk_numlock = 0x90;
Vk_space = 0x20;
Vk_decimal = 0x6e;
Vk_subtract = 0x6d;

Vk_add = 0x6b;
Vk_divide = 0x6f;
Vk_multiply = 0x6a;
Vk_insert = 0x2d;

Vk_oem_1 = 0xba; // ';:' for us
Vk_oem_plus = 0xbb; // '+'

Vk_oem_minus = 0xbd ;//'-'

Vk_oem_2 = 0xbf ;//'/? 'For us
Vk_oem_3 = 0xc0 ;//''~ 'For us
Vk_oem_4 = 0xdb; // '[{' for us
Vk_oem_5 = 0xdc; // '\ |' for us
Vk_oem_6 = 0xdd; // ']}' for us
Vk_oem_7 = 0xde; // ''" 'for us
Vk_oem_period = 0xbe; // '.>'
Vk_oem_comma = 0xbc; // ', <'
Vk_shift = 0x10;
Vk_control = 0x11;
Vk_menu = 0x12;
Vk_lwin = 0x5b;
Vk_rwin = 0x5c;
Vk_apps = 0x5d;

Vk_lshift = 0xa0;
Vk_rshift = 0xa1;
Vk_lcontrol = 0xa2;
Vk_rcontrol = 0xa3;
Vk_lmenu = 0xa4;
Vk_rmenu = 0xa5;

Vk_snapshot = 0x2c;
Vk_scroll = 0x91;
Vk_pause = 0x13;
Vk_home = 0x24;

Vk_next = 0x22;
Vk_prior = 0x21;
Vk_end = 0x23;

Vk_numpad0 = 0x60;
Vk_numpad1 = 0x61;
Vk_numpad2 = 0x62;
Vk_numpad3 = 0x63;
Vk_numpad4 = 0x64;
Vk_numpad5 = 0x65;
Vk_numpad5nothing = 0x0c;
Vk_numpad6 = 0x66;
Vk_numpad7 = 0x67;
Vk_numpad8 = 0x68;
Vk_numpad9 = 0x69;

Keyeventf_extendedkey = 0x0001;
Keyeventf_keyup = 0x0002;

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.