模擬鍵盤滑鼠事件 自己做外掛程式

2021-08-23 13:20:17 字數 1754 閱讀 6292

兩種方法:

1.sendmessage or postmessage

2.keybd_event,mouse_event

前者更強大,指定hwnd後可以後台傳送,而後者只能夠傳送前台資訊..也就是必須視窗最前

簡單的舉例:

方法2setcursorpos(x,y);

mouse_event(mouseeventf_leftdown,0,0,0,0);

mouse_event(mouseeventf_leftup,0,0,0,0);

keybd_event(k,0,0,0);

keybd_event(k,0,keyeventf_keyup,0);

方法1以當前程式的某個輸入框為例:

hwnd tw2 = getdlgitem(idc_edit1)->m_hwnd;

::sendmessage(tw2,wm_char,s[i],0);

否個按鈕:

hwnd tw3 = getdlgitem(idok)->m_hwnd;

::sendmessage(tw3,wm_lbuttondown,0,0);

::sendmessage(tw3,wm_lbuttonup,0,0);

以記事本為例

wnd = ::findwindow("notepad", null);

wnd = findwindowex(wnd,0,"edit",null);

::sendmessage(tw2,wm_char,s[i],0);

有人就說了,我不知道名字叫edit啊,有下面的方法:

cwnd * pwnd = findwindow("notepad", null);

cwnd * p2 = pwnd->gettopwindow();

wnd = p2->m_hwnd;

::sendmessage(tw2,wm_char,s[i],0);

又有人說了,如果連notepad也不知道呢...

我說,程序id總知道了吧...遍歷程序池得到想要的程序id,然後找到指定id的hwnd

struct enumparam

;bool callback enumwinproc(hwnd hwnd, lparam lparam)

return true;

}enumparam ep;

startupinfo si;

process_information pi;

ep.hmainwnd = null;

memset(&si, 0, sizeof(si));

si.cb = sizeof(startupinfo);

if (createprocess(null,"notepad.exe c:.txt",

null,null,false,0,null,null,&si,&pi))

//enumwindows((wndenumproc)enumwinproc, (long)&ep);

}//此時的 ep.hmainwnd 就是你要的nodepad.exe視窗的控制代碼

//接下來由hwnd得到cwnd *

wnd = ep.hmainwnd;

if(wnd == null) afxmessagebox("fasle");

cwnd * tc = fromhandle(wnd);

//獲取

wnd = tc->gettopwindow()->m_hwnd;

::sendmessage(tw2,wm_char,s[i],0);

//ok啦

模擬鍵盤事件與滑鼠事件

模擬事件 title head body button id mouseeventtrigger 鍵盤模擬按鈕事件 button button id keyboardeventtrigger 按鈕模擬鍵盤事件 button body script varbtn1 document.getelemen...

C 模擬鍵盤滑鼠事件

1.模擬鍵盤事件 system.windows.forms.sendkeys 以下是 sendkeys 的一些特殊鍵 表。鍵 backspace 或 break caps lock del 或 delete 或 down arrow 下箭頭鍵 end enter 或 esc help home in...

Unity 模擬滑鼠及鍵盤事件

在專案中遇到要模擬鍵盤事件,在網上查資料,整理了一下模擬鍵盤按鍵,順便把滑鼠事件一起整理下,以後也許用的到。主要還是用到user32.dll。鍵盤模擬 鍵盤鍵與虛擬鍵碼對照表 字母和數字鍵 數字小鍵盤的鍵 功能鍵 其它鍵 鍵 鍵碼 鍵 鍵碼 鍵 鍵碼 鍵 鍵碼 a 65 0 96 f1 112 ba...