2008年12月1日 星期一

[轉貼]模擬滑鼠及鍵盤事件

由虛擬碼而知當
key=1表示您按下了滑鼠的左鍵
key=2表示您按下了滑鼠的右鍵依此類推...

keybd_event();是模擬鍵盤的動作(按下某個鍵)
mouse_event();是模擬滑鼠的動作
==================================
如何用程式觸發滑鼠按鍵的事件(如何模擬滑鼠的按鍵)
模擬滑鼠按左鍵:
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);// click down
模擬滑鼠按Double Click:
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);// click down
模擬滑鼠按右鍵:
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);// click down
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);// click down
==================================
如何用程式觸發鍵盤按鍵的事件(模擬鍵盤按鍵)
對Form1觸發Tab按鍵按下事件:
PostMessage(form1.Handle, WM_KEYDOWN, VK_TAB, 0);
對Edit1觸發Enter按鍵按下事件:
PostMessage(edit1.Handle, WM_KEYDOWN, VK_RETURN, 0);
對Edit1觸發Enter按鍵放開事件:
PostMessage(edit1.Handle, WM_KEYUP, VK_F1, 0);
對Edit1觸發 1 按鍵按下事件:
PostMessage(edit1.Handle, WM_KEYDOWN, 49, 0);
對Edit1觸發 A 按鍵按下事件:
PostMessage(edit1.Handle, WM_KEYDOWN, 65, 0);
==================================

沒有留言: