模仿键盘 Ctrl+V ????????????(50分)

  • 主题发起人 主题发起人 yhneo
  • 开始时间 开始时间
Y

yhneo

Unregistered / Unconfirmed
GUEST, unregistred user!
keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL,0), KEYEVENTF_EXTENDEDKEY,0);<br>keybd_event(byte('v'), MapVirtualKey(byte('v'),1), KEYEVENTF_EXTENDEDKEY,0);<br>keybd_event(byte('v'),MapVirtualKey(byte('v'),1), KEYEVENTF_KEYUP,0);<br>keybd_event( VK_CONTROL, MapVirtualKey(VK_CONTROL,0),KEYEVENTF_KEYUP,0);<br>那里不对?[:(]<br>
 
稍微修改 :<br><br>keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL,0), 0,0);<br>keybd_event(byte('v'), MapVirtualKey(byte('v'),0), 0,0);<br>keybd_event(byte('v'),MapVirtualKey(byte('v'),0), KEYEVENTF_KEYUP,0);<br>keybd_event( VK_CONTROL, MapVirtualKey(VK_CONTROL,0),KEYEVENTF_KEYUP,0);<br><br>OK!<br>
 
卷起千堆雪tyn已回答的很准确了。
 
Although keybd_event passes an OEM-dependent hardware scan code to Windows, <br>applications should not use the scan code. <br>Windows converts scan codes to virtual-key codes internally and clears <br>the up/down bit in the scan code before passing it to applications. <br><br>用sendmessage吧<br>
 
请教:为何不能模拟Ctrl和Alt之间的Win键,以便弹出开始菜单;<br>keybd_event(91, MapVirtualKey(91,0), 0,0);<br>keybd_event(91,MapVirtualKey(91,0), KEYEVENTF_KEYUP,0);<br>那里不对?
 
keybd_event(91, MapVirtualKey(91,0), 1,0);<br>keybd_event(91,MapVirtualKey(91,0), 2,0);<br>
 
我有更简单的办法<br>呵呵,就是向当前的窗口发送粘贴消息就OK了
 
直接向控件发送粘贴消息:<br>&nbsp; &nbsp;sendMessage(edit1.handle,WM_PASTE,0,0);<br>
 
edit1.handle<br>换成GetForegroundWindow就OK了
 
后退
顶部