PostMessage send ALT key combination to Windows window

Source: Internet
Author: User

PostMessage send ALT key combination to Windows window


About sending an ALT key combination to the Windows window, this is a classic question Ah, in the Internet to find a bit, ask people n more, the way is similar,

But there is no good problem solving.

Before finding a code that can be sent correctly: (Alt+a)

PostMessage (hwnd,wm_syskeydown,vk_menu,0);

PostMessage (hwnd,wm_syskeydown,0x41,0);

Sleep (50);

PostMessage (hwnd,wm_syskeyup,0x41,0);

PostMessage (hwnd,wm_syskeyup,vk_menu,0);

It was explained that the system was sent two messages when the combination was pressed.

But see the Win32 SDK, feel on the hair once on it can ...

Occasionally see a description of the last parameter, something found! First look at Wm_syskeydown's help.

The WM_SYSKEYDOWN message is posted to the window with the keyboard focus, the user holds down the ALT key and then PR Esses another key. It also occurs when no window currently had the the keyboard focus; The WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these a contexts by checking the context code in the Lkeyda Ta parameter.

Wm_syskeydown
Nvirtkey = (int) WParam; Virtual-key Code
Lkeydata = LParam; Key data


Parameters

Nvirtkey

Value of WParam. Specifies the Virtual-key code of the key being pressed.

Lkeydata

Value of LParam. Specifies the repeat count, scan code, Extended-key flag, context code, previous Key-state flag, and Transition-state flag , as shown in the following table:

Value Description
0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the the user holding down the key.
16-23 specifies the scan code. The value depends on the original equipment manufacturer (OEM).
Specifies whether the key is a extended key, such as the right-hand ALT and CTRL keys that appear in an enhanced 101- or 102-key keyboard. The value is 1 if it's an extended key; Otherwise, it is 0.
25-28 Reserved; Do not use.
Specifies the context code. The value is 1 if the ALT key is a while and the key is pressed; It is a 0 if the Wm_syskeydown message is posted to the active window because no window has the the keyboard focus.
Specifies the previous key state. The value is 1 if the key is a down before the message is sent, or it's 0 if the key is up.
Specifies the transition state. The value is always 0 for a wm_syskeydown message.


The previous modified Keydata 16-23 bit is vk_menu, the 30th bit parameter is 1, but no effect

Please see bit 29 for instructions!!

The value is 1 if the ALT key is a while and the key is pressed;

A value of 1 indicates that the ALT key is pressed! Isn't that what I need? The 29 bit is then set to 1, and the function call becomes

PostMessage (hwnd,wm_syskeydown,0x41,1<<29);

After testing, found that this is the effect of Alt+a!! It turned out to be so simple, but why so many people so complicated, I was looking at the time is also confused Ah, wasted more than n hours.

Similar to having a wm_syskeyup,wm_syschar (this does not know what to do with)

Record it before it becomes a fool to find the information.

PostMessage (edit1.handle,wm_keydown,vk_down,$20000000)

Ctrl: $10000000;
Shift: $08000000;
alt:20000000

Delphi Keyboard key Pseudo code

If key = Chr (Vk_return) then ...

Constant name hexadecimal value decimal value corresponding key
Vk_lbutton 01 1 left mouse button
Vk_rbutton 02 2 right mouse button
Vk-cancel 3 Contol-break execution
Vk_mbutton 04 4 middle mouse button (three-button mouse)
Vk_back 8 backspace key
Vk_tab 9 TAB Key
Vk_clear 0C CLEAR Key
Vk_return 0D Enter key
Vk_shift SHIFT Key
Vk_control CTRL key
Vk_menu ALT key
Vk_pause PAUSE Key
Vk_capital CAPS LOCK key
Vk_escape 1 B ESE key
Vk_space SPACEBAR key
Vk_prior Page up key
Vk_next Page domw Key
Vk_end the END key
Vk_home HOME button
Vk_left to the left ARROW key (←)
Vk_up Up ARROW key (↑)
Vk_right right ARROW key (→)
Vk_down arrow key (↓)
Vk_select SELECT Key
Vk_execute 2B EXECUTE Key
Vk_snapshot 2C Print Screen key
Vk_insert 2D INS key
Vk_delete 2E-del key
Vk_help 2F Help Key
Vk_0 30 48 0 Key
Vk_1 31 49 1 key
Vk_2 32 50 2 Key
Vk_3 33 51 3 Key
Vk_4 34 52 4 Key
Vk_5 35 53 5 key
Vk_6 36 54 6 Key
Vk_7 37 55 7 key
Vk_8 38 56 8 Key
Vk_9 39 57 9 key
Vk_a A Key
Vk_b B Key
Vk_c-C Key
Vk_d-D Key
Vk_e E Key
Vk_f F Key
Vk_g G Key
Vk_h H Key
Vk_i I Key
Vk_j 4 a J key
Vk_k 4 B K key
vk_l 4C L Key
Vk_m 4D M Key
Vk_n 4E + N key
Vk_o 4F O Key
Vk_p P Key
Vk_q Yi Ba Q key
Vk_r-G-R key
vk_s-S-Key
vk_t T Key
Vk_u U-Key
Vk_v V-Key
Vk_w W Key
Vk_x X Key
Vk_y Y Key
VK_BZ 5A z Key
VK_NUMPAD0 60 96 number Key 0 key
VK_NUMPAD1 61 97 number Key 1 key
VK_NUMPAD2 62 98 Number Key 2 key
VK_NUMPAD3 63 99 number Key 3 key
VK_NUMPAD4 64 100 number key 4 key
VK_NUMPAD5 65 101 Number Key 5 key
VK_NUMPAD6 66 102 Number Key 6 key
VK_NUMPAD7 67 103 Number Key 7 key
VK_NUMPAD8 68 104 Number Key 8 key
VK_NUMPAD9 69 105 Number Key 9 key
Vk_multiply 6A 106 * Key
Vk_add 6B 107 + key
Vk_separator 6C 108 SEPARATOR Key
Vk_subtract 6D 109-Key
Vk_decimal 6E 110. Key
Vk_divide 6F 111 Key
VK_F1 F1 Key
VK_F2 113 F2 Key
VK_F3 F3 Key
Vk_f4 F4 Key
Vk_f5 F5 Key
VK_F6 117 F6 Key
VK_F7 118 F7 Key
Vk_f8 119 F8 Key
VK_F9 F9 Key
VK_F10 121 F10 Key
VK_F11 7A 122 F11 Key
VK_F12 7B 123 F12 Key
Vk_numlock 144 Num Lock key
Vk_scroll 145 SCROLL Lock key

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.