请问我模拟按键 我想模拟← → 用到keybd_event函数 那么我该怎么用呢? 是不是中间加个Sleep?但是我加了程序就未响应了
void CAjDlg::OnButton1()
{
SetTimer(1,300,NULL);//启动时间控制器.时间为300豪秒
}
void CAjDlg::OnTimer(UINT nIDEvent) //时间控制器
{
if(nIDEvent==1){
keybd_event(VK_LEFT,MapVirtualKey(VK_LEFT,0),0,0);
keybd_event(VK_LEFT,MapVirtualKey(VK_LEFT,0),KEYEVENTF_KEYUP,0);
Sleep(1000);
keybd_event(VK_RIGHT,MapVirtualKey(VK_RIGHT,0),0,0);
keybd_event(VK_RIGHT,MapVirtualKey(VK_RIGHT,0),KEYEVENTF_KEYUP,0);
}
}
我用在当前程序 加了个文本框 试了未响应 不是在当前程序却没反映
而我用了自动按键 却可以用 这是想连续按两个键却不能用
void CAjDlg::OnButton1()
{
SetTimer(1,300,NULL);//启动时间控制器.时间为300豪秒
}
void CAjDlg::OnTimer(UINT nIDEvent) //时间控制器
{
if(nIDEvent==1){
keybd_event(VK_LEFT,MapVirtualKey(VK_LEFT,0),0,0);
keybd_event(VK_LEFT,MapVirtualKey(VK_LEFT,0),KEYEVENTF_KEYUP,0);
Sleep(1000);
keybd_event(VK_RIGHT,MapVirtualKey(VK_RIGHT,0),0,0);
keybd_event(VK_RIGHT,MapVirtualKey(VK_RIGHT,0),KEYEVENTF_KEYUP,0);
}
}
我用在当前程序 加了个文本框 试了未响应 不是在当前程序却没反映
而我用了自动按键 却可以用 这是想连续按两个键却不能用
SendInput
The SendInput function synthesizes keystrokes, mouse motions, and button clicks.UINT SendInput(
UINT nInputs, // count of input events
LPINPUT pInputs, // array of input events
int cbSize // size of structure
);
Parameters
nInputs
[in] Specifies the number of structures in the pInputs array.
pInputs
[in] Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream.
cbSize
[in] Specifies the size, in bytes, of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail.