发送Keydown消息,可忘了怎么带Ctrl(100分)

  • 主题发起人 主题发起人 Kang
  • 开始时间 开始时间
K

Kang

Unregistered / Unconfirmed
GUEST, unregistred user!
发送WM_KEYDOWN,只记得发送Key,忘了怎么发送Ctrl,Alt信息<br>书不在身边,哪位能告诉一下?
 
(ssctrl in shift)
 
SendMessage(handle,wm_keydown,vk_control,0);//發送Ctrl信息<br>SendMessage(handle,wm_keydown,vk_menu,0);//發送Alt信息
 
我要发送Ctrl+Home Ctrl+end等KeyDown ,Windows编程书都有,只是我现在没书,又出不去
 
WM_KEYDOWN &nbsp;<br>nVirtKey = (int) wParam; &nbsp; &nbsp;// virtual-key code wParam中放的就是键值。<br>lKeyData = lParam; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// key data lParam中记录了一些有关的数据,如击键次数,扫描码什么的。<br><br>Parameters<br><br>nVirtKey<br><br>Value of wParam. Specifies the virtual-key code of the nonsystem key. <br><br>lKeyData<br><br>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: <br><br>Value Description<br>0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user holding down the key.<br>16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).<br>24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.<br>25-28 Reserved; do not use.<br>29 Specifies the context code. The value is always 0 for a WM_KEYDOWN message.<br>30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.<br>31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN message.<br><br><br><br>键值表:<br>Symbolic constant name Value (hexadecimal) Mouse or keyboard equivalent<br>VK_LBUTTON 01 Left mouse button <br>VK_RBUTTON 02 Right mouse button <br>VK_CANCEL 03 Control-break processing <br>VK_MBUTTON 04 Middle mouse button (three-button mouse) <br>&nbsp;? 05-07 Undefined <br>VK_BACK 08 BACKSPACE key <br>VK_TAB 09 TAB key <br>&nbsp;? 0A-0B Undefined <br>VK_CLEAR 0C CLEAR key <br>VK_RETURN 0D ENTER key <br>&nbsp;? 0E-0F Undefined <br>VK_SHIFT 10 SHIFT key <br>VK_CONTROL 11 CTRL key <br>VK_MENU 12 ALT key <br>VK_PAUSE 13 PAUSE key <br>VK_CAPITAL 14 CAPS LOCK key <br>&nbsp;? 15-19 Reserved for Kanji systems <br>&nbsp;? 1A Undefined <br>VK_ESCAPE 1B ESC key <br>&nbsp;? 1C-1F Reserved for Kanji systems <br>VK_SPACE 20 SPACEBAR <br>VK_PRIOR 21 PAGE UP key <br>VK_NEXT 22 PAGE DOWN key <br>VK_END 23 END key <br>VK_HOME 24 HOME key <br>VK_LEFT 25 LEFT ARROW key <br>VK_UP 26 UP ARROW key <br>VK_RIGHT 27 RIGHT ARROW key <br>VK_DOWN 28 DOWN ARROW key <br>VK_SELECT 29 SELECT key <br>&nbsp;? 2A Original equipment manufacturer (OEM) specific <br>VK_EXECUTE 2B EXECUTE key <br>VK_SNAPSHOT 2C PRINT SCREEN key for Windows 3.0 and later <br>VK_INSERT 2D INS key <br>VK_DELETE 2E DEL key <br>VK_HELP 2F HELP key <br>VK_0 30 0 key <br>VK_1 31 1 key <br>VK_2 32 2 key <br>VK_3 33 3 key <br>VK_4 34 4 key <br>VK_5 35 5 key <br>VK_6 36 6 key <br>VK_7 37 7 key <br>VK_8 38 8 key <br>VK_9 39 9 key <br>&nbsp;? 3A-40 Undefined <br>VK_A 41 A key <br>VK_B 42 B key <br>VK_C 43 C key <br>VK_D 44 D key <br>VK_E 45 E key <br>VK_F 46 F key <br>VK_G 47 G key <br>VK_H 48 H key <br>VK_I 49 I key <br>VK_J 4A J key <br>VK_K 4B K key <br>VK_L 4C L key <br>VK_M 4D M key <br>VK_N 4E N key <br>VK_O 4F O key <br>VK_P 50 P key <br>VK_Q 51 Q key <br>VK_R 52 R key <br>VK_S 53 S key <br>VK_T 54 T key <br>VK_U 55 U key <br>VK_V 56 V key <br>VK_W 57 W key <br>VK_X 58 X key <br>VK_Y 59 Y key <br>VK_Z 5A Z key <br>VK_LWIN 5B Left Windows key (Microsoft Natural Keyboard) <br>VK_RWIN 5C Right Windows key (Microsoft Natural Keyboard) <br>VK_APPS 5D Applications key (Microsoft Natural Keyboard) <br>&nbsp;? 5E-5F Undefined <br>VK_NUMPAD0 60 Numeric keypad 0 key <br>VK_NUMPAD1 61 Numeric keypad 1 key <br>VK_NUMPAD2 62 Numeric keypad 2 key <br>VK_NUMPAD3 63 Numeric keypad 3 key <br>VK_NUMPAD4 64 Numeric keypad 4 key <br>VK_NUMPAD5 65 Numeric keypad 5 key <br>VK_NUMPAD6 66 Numeric keypad 6 key <br>VK_NUMPAD7 67 Numeric keypad 7 key <br>VK_NUMPAD8 68 Numeric keypad 8 key <br>VK_NUMPAD9 69 Numeric keypad 9 key <br>VK_MULTIPLY 6A Multiply key <br>VK_ADD 6B Add key <br>VK_SEPARATOR 6C Separator key <br>VK_SUBTRACT 6D Subtract key <br>VK_DECIMAL 6E Decimal key <br>VK_DIVIDE 6F Divide key <br>VK_F1 70 F1 key <br>VK_F2 71 F2 key <br>VK_F3 72 F3 key <br>VK_F4 73 F4 key <br>VK_F5 74 F5 key <br>VK_F6 75 F6 key <br>VK_F7 76 F7 key <br>VK_F8 77 F8 key <br>VK_F9 78 F9 key <br>VK_F10 79 F10 key <br>VK_F11 7A F11 key <br>VK_F12 7B F12 key <br>VK_F13 7C F13 key <br>VK_F14 7D F14 key <br>VK_F15 7E F15 key <br>VK_F16 7F F16 key <br>VK_F17 80H F17 key <br>VK_F18 81H F18 key <br>VK_F19 82H F19 key <br>VK_F20 83H F20 key <br>VK_F21 84H F21 key <br>VK_F22 85H F22 key <br>VK_F23 86H F23 key <br>VK_F24 87H F24 key <br>&nbsp;? 88-8F Unassigned <br>VK_NUMLOCK 90 NUM LOCK key <br>VK_SCROLL 91 SCROLL LOCK key <br>&nbsp;? 92-B9 Unassigned <br>&nbsp;? BA-C0 OEM specific <br>&nbsp;? C1-DA Unassigned <br>&nbsp;? DB-E4 OEM specific <br>&nbsp;? E5 Unassigned <br>&nbsp;? E6 OEM specific <br>&nbsp;? E7-E8 Unassigned <br>&nbsp;? E9-F5 OEM specific <br>VK_ATTN F6 Attn key<br>VK_CRSEL F7 CrSel key<br>VK_EXSEL F8 ExSel key<br>VK_EREOF F9 Erase EOF key<br>VK_PLAY FA Play key<br>VK_ZOOM FB Zoom key<br>VK_NONAME FC Reserved for future use. <br>VK_PA1 FD PA1 key<br>VK_OEM_CLEAR FE Clear key <br>
 
我印象中Ctrl是否按下是和VK_HOME一起在lParam中体现的,Ctrl,Alt等是根据lParam的某位是否<br>为1来设置或判断是否按了Ctrl或Alt,哪位帮我查下书,介绍Windows消息的书上好象都有的
 
你可以:<br>&nbsp;MapVirtualKey(VK_CONTROL,1);<br>&nbsp;sendmessage(Handle,wm_keydown,VK_HOME,0);<br>達到同時發送Ctrl+Home的目的。
 
以上几位的都没试过吧?<br>不过我自己已经解决了,但却发现只有RichEdit有输入焦点时才能接受Ctrl+home,而PageDown<br>却不需要任何条件,可能是Windows自己的原因了,
 
还有没有别的方法?
 
可以用KEYBD_EVENT来模拟键盘操作
 
&nbsp;keybd_event( VK_MENU, MapVirtualKey( VK_MENU, 0 ), 0 , 0 ); &nbsp; &nbsp; // Alt down <br>&nbsp; keybd_event( VK_DOWN, MapVirtualKey( VK_DOWN, 0 ), 0 , 0 ); &nbsp; &nbsp; // down arrow key down <br>&nbsp; keybd_event( VK_DOWN, MapVirtualKey( VK_DOWN, 0 ), KEYEVENTF_KEYUP , 0 ); &nbsp;// down arrow key up <br>&nbsp; keybd_event( VK_MENU, MapVirtualKey( VK_MENU, 0 ), KEYEVENTF_KEYUP , 0 ); &nbsp;// Alt key up <br><br>另加补充:<br>Ctrl: VK_CONTROL<br>SHIFT:VK_SHIFT<br>TAB: &nbsp;VK_TAB<br>'A': &nbsp;byte('A') &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
 
获得了其他程序一个窗口的句柄,如何模拟按键ALT-R发送给它啊?<br>
 
Alt好像没法发。。。。
 
说错了,Alt的虚拟键值是VK_Menu,因此要模拟一次Alt按键的话可以:<br>keybd_event(VK_Menu, 0, 0, 0); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // 按下<br>keybd_event(VK_Menu, 0, KEYEVENTF_KEYUP, 0); &nbsp; // 松开
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
I
回复
0
查看
633
import
I
后退
顶部