鼠标消息
在窗口显示区域鼠标消息 | |
WM_MOUSEMOVE | 当鼠标在窗口的显示区域移动时 |
WM_LBUTTONDOWN | 按下鼠标左键 |
WM_LBUTTONUP | 释放鼠标左键 |
WM_LBUTTONDBLCLK | 双击鼠标左键 |
WM_MBUTTONDOWN | 按下鼠标中键 |
WM_MBUTTONUP | 释放鼠标中键 |
WM_MBUTTONDBLCLK | 双击鼠标中键 |
WM_RBUTTONDOWN | 按下鼠标右键 |
WM_RBUTTONUP | 释放鼠标右键 |
WM_RBUTTONDBLCLK | 双击鼠标右键 |
wParam为鼠标按键以及Shift和Ctrl键的状态 lParam为鼠标的显示区域x坐标y坐标(高字节为x,低字节为y) | |
WM_NCHITTEST | 鼠标命中测试 |
Windows根据它来产生与鼠标位置相关的所有其它鼠标消息 wParam unused lParam 屏幕坐标x,y | |
WM_MOUSEWHEEL | 鼠标滚轮转动 |
wParam的低字组包含一系列的旗标,用于表示鼠标按键、Shift与Ctrl键的状态。 wParam的高字组保存一个「delta」值,该值目前可以是120或-120,向前转动或向后转动。值120或-120表示文件将分别向上或向下卷动三行。 lParam为鼠标的屏幕坐标 | |
显示区域鼠标消息和显示区域鼠标消息wParam 的位屏蔽有 | |
MK_LBUTTON按下左键 MK_MBUTTON按下中键 MK_RBUTTON按下右键 MK_SHIFT按下Shift键 MK_CONTROL按下Ctrl键 |
在窗口非显示区域鼠标消息 | |
WM_NCMOUSEMOVE | 当鼠标在窗口的显示区域移动时 |
WM_NCLBUTTONDOWN | 按下鼠标左键 |
WM_NCLBUTTONUP | 释放鼠标左键 |
WM_NCLBUTTONDBLCLK | 双击鼠标左键 |
WM_NCMBUTTONDOWN | 按下鼠标中键 |
WM_NCMBUTTONUP | 释放鼠标中键 |
WM_NCMBUTTONDBLCLK | 双击鼠标中键 |
WM_NCRBUTTONDOWN | 按下鼠标右键 |
WM_NCRBUTTONUP | 释放鼠标右键 |
WM_NCRBUTTONDBLCLK | 双击鼠标右键 |
wParam命中的区域 | |
lParam为鼠标的显示区域x坐标+y坐标 |
键盘消息
虚拟码 | ||
虚拟键码 | 值 | 对应键 |
VK_LBUTTON | 1 | Left mouse button |
VK_RBUTTON | 2 | Right mouse button |
VK_CANCEL | 3 | Control-break processing |
VK_MBUTTON | 4 | Middle mouse button (three-button mouse) |
VK_XBUTTON1 | 5 | Windows 2000/XP: X1 mouse button |
VK_XBUTTON2 | 6 | Windows 2000/XP: X2 mouse button |
VK_BACK | 8 | Backspace |
VK_TAB | 9 | Tab |
VK_CLEAR | 12 | Clear |
VK_RETURN | 13 | Enter |
VK_SHIFT | 16 | Shift |
VK_CONTROL | 17 | Ctrl |
VK_MENU | 18 | Alt |
VK_PAUSE | 19 | Pause |
VK_CAPITAL | 20 | Caps Lock |
VK_KANA | 21 | IME Hanguel mode (maintained for compatibility; use VK_HANGUL) |
VK_HANGUL | 21 | IME Hangul mode |
VK_JUNJA | 23 | IME Junja mode |
VK_FINAL | 24 | IME final mode |
VK_HANJA | 25 | IME Hanja mode |
VK_KANJI | 25* | IME Kanji mode |
VK_ESCAPE | 27 | Esc |
VK_CONVERT | 28 | IME convert |
VK_NONCONVERT | 29 | IME nonconvert |
VK_ACCEPT | 30 | IME accept |
VK_MODECHANGE | 31 | IME mode change request |
VK_SPACE | 32 | Space |
VK_PRIOR | 33 | Page Up |
VK_NEXT | 34 | Page Down |
VK_END | 35 | End |
VK_HOME | 36 | Home |
VK_LEFT | 37 | Left Arrow |
VK_UP | 38 | Up Arrow |
VK_RIGHT | 39 | Right Arrow |
VK_DOWN | 40 | Down Arrow |
VK_SELECT | 41 | Select |
VK_PRINT | 42 | |
VK_EXECUTE | 43 | Execute |
VK_SNAPSHOT | 44 | Snapshot |
VK_INSERT | 45 | Insert |
VK_DELETE | 46 | Delete |
VK_HELP | 47 | Help |
48 | 0 | |
49 | 1 | |
50 | 2 | |
51 | 3 | |
52 | 4 | |
53 | 5 | |
54 | 6 | |
55 | 7 | |
56 | 8 | |
57 | 9 | |
65 | A | |
66 | B | |
67 | C | |
68 | D | |
69 | E | |
70 | F | |
71 | G | |
72 | H | |
73 | I | |
74 | J | |
75 | K | |
76 | L | |
77 | M | |
78 | N | |
79 | O | |
80 | P | |
81 | Q | |
82 | R | |
83 | S | |
84 | T | |
85 | U | |
86 | V | |
87 | W | |
88 | X | |
89 | Y | |
90 | Z | |
VK_LWIN | 91 | leftWindows key |
VK_RWIN | 92 | rightWindows key |
VK_APPS | 93 | Applications key |
VK_SLEEP | 95 | Computer Sleep key |
VK_NUMPAD0 | 96 | Numeric keypad 0 |
VK_NUMPAD1 | 97 | Numeric keypad 1 |
VK_NUMPAD2 | 98 | Numeric keypad 2 |
VK_NUMPAD3 | 99 | Numeric keypad 3 |
VK_NUMPAD4 | 100 | Numeric keypad 4 |
VK_NUMPAD5 | 101 | Numeric keypad 5 |
VK_NUMPAD6 | 102 | Numeric keypad 6 |
VK_NUMPAD7 | 103 | Numeric keypad 7 |
VK_NUMPAD8 | 104 | Numeric keypad 8 |
VK_NUMPAD9 | 105 | Numeric keypad 9 |
VK_MULTIPLY | 106 | Numeric keypad * |
VK_ADD | 107 | Numeric keypad + |
VK_SEPARATOR | 108 | Numeric keypad Enter |
VK_SUBTRACT | 109 | Numeric keypad - |
VK_DECIMAL | 110 | Numeric keypad . |
VK_DIVIDE | 111 | Numeric keypad / |
VK_F1 | 112 | F1 |
VK_F2 | 113 | F2 |
VK_F3 | 114 | F3 |
VK_F4 | 115 | F4 |
VK_F5 | 116 | F5 |
VK_F6 | 117 | F6 |
VK_F7 | 118 | F7 |
VK_F8 | 119 | F8 |
VK_F9 | 120 | F9 |
VK_F10 | 121 | F10 |
VK_F11 | 122 | F11 |
VK_F12 | 123 | F12 |
VK_F13 | 124 | F13 |
VK_F14 | 125 | F14 |
VK_F15 | 126 | F15 |
VK_F16 | 127 | F16 |
VK_F17 | 128 | F17 |
VK_F18 | 129 | F18 |
VK_F19 | 130 | F19 |
VK_F20 | 131 | F20 |
VK_F21 | 132 | F21 |
VK_F22 | 133 | F22 |
VK_F23 | 134 | F23 |
VK_F24 | 135 | F24 |
VK_NUMLOCK | 144 | Num Lock |
VK_SCROLL | 145 | Scroll |
VK_LSHIFT | 160 | left shift key |
VK_RSHIFT | 161 | right shift key |
VK_LCONTROL | 162 | left ctrl key |
VK_RCONTROL | 163 | right ctrl key |
VK_LMENU | 164 | left alt key |
VK_RMENU | 165 | right alt key |
VK_BROWSER_BACK | 166 | Windows 2000/XP: Browser Back key |
VK_BROWSER_FORWARD | 167 | Windows 2000/XP: Browser Forward key |
VK_BROWSER_REFRESH | 168 | Windows 2000/XP: Browser Refresh key |
VK_BROWSER_STOP | 169 | Windows 2000/XP: Browser Stop key |
VK_BROWSER_SEARCH | 170 | Windows 2000/XP: Browser Search key |
VK_BROWSER_FAVORITES | 171 | Windows 2000/XP: Browser Favorites key |
VK_BROWSER_HOME | 172 | Windows 2000/XP: Browser Start and Home key |
VK_VOLUME_MUTE | 173 | Windows 2000/XP: Volume Mute key |
VK_VOLUME_DOWN | 174 | Windows 2000/XP: Volume Down key |
VK_VOLUME_UP | 175 | Windows 2000/XP: Volume Up key |
VK_MEDIA_NEXT_TRACK | 176 | Windows 2000/XP: Next Track key |
VK_MEDIA_PREV_TRACK | 177 | Windows 2000/XP: Previous Track key |
VK_MEDIA_STOP | 178 | Windows 2000/XP: Stop Media key |
VK_MEDIA_PLAY_PAUSE | 179 | Windows 2000/XP: Play/Pause Media key |
VK_LAUNCH_MAIL | 180 | Windows 2000/XP: Start Mail key |
VK_LAUNCH_MEDIA_SELECT | 181 | Windows 2000/XP: Select Media key |
VK_LAUNCH_APP1 | 182 | Windows 2000/XP: Start Application 1 key |
VK_LAUNCH_APP2 | 183 | Windows 2000/XP: Start Application 2 key |
VK_OEM_1 | 186 | ; : |
VK_OEM_PLUS | 187 | = + |
VK_OEM_COMMA | 188 | , |
VK_OEM_MINUS | 189 | - _ |
VK_OEM_PERIOD | 190 | . |
VK_OEM_2 | 191 | / ? |
VK_OEM_3 | 192 | ` ~ |
VK_OEM_4 | 219 | [ { |
VK_OEM_5 | 220 | \ | |
VK_OEM_6 | 221 | ] } |
VK_OEM_7 | 222 | ' " |
VK_OEM_8 | 223 | Used for miscellaneous characters; it can vary by keyboard. |
VK_OEM_102 | 226 | Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard |
VK_PACKET | 231 | Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP |
VK_PROCESSKEY | 229 | Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key |
VK_ATTN | 246 | Attn key |
VK_CRSEL | 247 | CrSel key |
VK_EXSEL | 248 | ExSel key |
VK_EREOF | 249 | Erase EOF key |
VK_PLAY | 250 | Play key |
VK_ZOOM | 251 | Zoom key |
VK_NONAME | 252 | Reserved |
VK_PA1 | 253 | PA1 key |
VK_OEM_CLEAR | 254 | Clear key |
关于键盘消息的一些相关概念
扫描码和虚拟码 |
|
输入焦点 |
|
注意:每当用户按下或释放某一个键时,会产生一个中断,该中断激活键盘驱动程序KEYBOARD.DRV来对键盘中断进行处理.KEYBOARD.DRV程序会根据用户的不同操作进行编码,然后调用Windows用户模块USER.EXE生成键盘消息,并将该消息发送到消息队列中等候处理
系统键消息 | 系统键消息指由Aft键和其他键组合而产生的按键消息.当系统键被按下时产生WM_ SYSKEYDOWN消息,当系统键被释放时产生WM_SYSKEYUP消息 |
Aft键与其他键形成的组合键通常用于对程序菜单和系统菜单进行选择,或用于在不同的程序之间进行切换.因此,系统键消息应该交由Windows进行处理,用户所编制的程序一般不处理系统键消息,而是将这些消息交由DefWindowProc函数进行处理.如果用户想对系统键消息进行处理,应该在处理完这些消息后,再将其发送给DefWindowProc函数,使得Windows系统能够正常工作 | |
非系统键消息 | l那些不使用Alt键组合的按键消息 |
Windows用8种不同的消息来传递不同的键盘事件 | ||
按键消息 | ||
消息 | 类型 | 含义 |
WM_SYSKEYDOWN | 系统 | 按下系统按键/组合按键 |
WM_SYSKEYUP | 系统 | 松开系统按键/组合按键 |
WM_KEYDOWN | 非系统 | 按下按键 |
WM_KEYUP | 非系统 | 松开按键 |
字符消息 | ||
消息 | 类型 | 含义 |
WM_SYSCHAR | 系统 | 系统字符 |
WM_SYSDEADCHAR | 系统 | 系统死字符 |
WM_CHAR | 非系统 | 字符 |
WM_DEADCHAR | 非系统 | 死字符 |
注意 | ||
|
键盘消息MSG结构体变量 | ||||||||||||||||
wParam域用于保存按键的虚拟键代码或字符的ASCII码.对于非字符消息,wParam域保存按键的虚拟健代码;对于字符消息,wParam域不保存字符的ASCII码 | ||||||||||||||||
lParam域则用于保存击键时产生的附加信息,实际上一个32位的lParam变量被分为六部分,记录了以下相关信息:重复次数、OEM扫描码、扩展键标志、关联键标志、前一击键状态和转换状态
|
按键消息的顺序 |
WM_KEYDOWN/WM_SYSKEYDOWN ↓ WM_CHAR/WM_SYSCHAR ↓ WM_KEYUP/WM_SYSKEYUP |
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 例如,按下并释放1键.按下1键所产生的消息和wParam的取值 消息 wParam变量取值 WM_KEYDOWN 虚拟码1 WM_CHAR ASCII码“1” WM_KEYUP 虚拟码1 |
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 例如,按下Shift键后再按下1键并释放,则依次产生如表所示的消息.按下Shift键后按健所产生的消息和wParam的取值 消息 wParam变量取值 WM_KEYDOWN 虚拟码 VK_SHIFT WM_KEYDOWN 虚拟码 VK_1 WM_CHAR ASCII码 “1” WM_KEYUP 虚拟码 VK_1 WM_KEYUP 虚拟码 VK_SHIFT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< |