c语言 怎样模拟鼠标键盘操作?
我获得了qq聊天窗口的句柄了,然后想用c程序模拟鼠标和键盘的操作,实现自动输入字符,自动点击发送按钮,达到自动聊天的功能,貌似更多用到windows编程,请问这怎样实现?...
我获得了qq聊天窗口的句柄了,然后想用 c 程序模拟鼠标和键盘的操作,实现自动输入字符,自动点击发送按钮,达到自动聊天的功能,貌似更多用到windows编程,请问这怎样实现?先给30 ,回答好了再加70,谢谢!望高手指点!
最主要的是怎样模拟键盘的打字操作,我现在可以实现鼠标自动点击输入框使之变成可输入状态了,这应该类似于输入法的操作,把文字写入文本框 展开
最主要的是怎样模拟键盘的打字操作,我现在可以实现鼠标自动点击输入框使之变成可输入状态了,这应该类似于输入法的操作,把文字写入文本框 展开
3个回答
展开全部
函数原型:
VOID keybd_event( BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo );
4个参数都是输入参数。
bVk:键名,例如: VK_NUMPAD7,VK_BACK, VK_TAB,VK_SHIFT,VK_F1,。。。
keybd_event(VK_MENU,0xb8,0 , 0); -- 按下Alt 键
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); -- 放开 Alt 键 (复位,弹上来)
===
下面程序模拟按 notepad 编辑器。等于C语言 system("notepad"); 弹出 记事本。
void simu_notepad()
{
keybd_event(VkKeyScan('N'),1,0,0);
keybd_event(VkKeyScan('N'),1,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('O'),0x98,0,0); keybd_event(VkKeyScan('O'),0x98,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('T'),0x94,0,0); keybd_event(VkKeyScan('T'),0x94,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('E'),0x92,0,0); keybd_event(VkKeyScan('E'),0x92,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('P'),0x99,0,0); keybd_event(VkKeyScan('P'),0x99,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('A'),0x9E,0,0); keybd_event(VkKeyScan('A'),0x9E,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('D'),0xA0,0,0); keybd_event(VkKeyScan('D'),0xA0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,1,0,0);
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
}
VOID keybd_event( BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo );
4个参数都是输入参数。
bVk:键名,例如: VK_NUMPAD7,VK_BACK, VK_TAB,VK_SHIFT,VK_F1,。。。
keybd_event(VK_MENU,0xb8,0 , 0); -- 按下Alt 键
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); -- 放开 Alt 键 (复位,弹上来)
===
下面程序模拟按 notepad 编辑器。等于C语言 system("notepad"); 弹出 记事本。
void simu_notepad()
{
keybd_event(VkKeyScan('N'),1,0,0);
keybd_event(VkKeyScan('N'),1,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('O'),0x98,0,0); keybd_event(VkKeyScan('O'),0x98,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('T'),0x94,0,0); keybd_event(VkKeyScan('T'),0x94,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('E'),0x92,0,0); keybd_event(VkKeyScan('E'),0x92,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('P'),0x99,0,0); keybd_event(VkKeyScan('P'),0x99,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('A'),0x9E,0,0); keybd_event(VkKeyScan('A'),0x9E,KEYEVENTF_KEYUP,0);
keybd_event(VkKeyScan('D'),0xA0,0,0); keybd_event(VkKeyScan('D'),0xA0,KEYEVENTF_KEYUP,0);
keybd_event(VK_RETURN,1,0,0);
keybd_event(VK_RETURN,1,KEYEVENTF_KEYUP,0);
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
模拟鼠标如下:
1、这里是鼠标左键按下和松开两个事件的组合即一次单击:
mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
2、模拟鼠标右键单击事件:
mouse_event (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 )
3、两次连续的鼠标左键单击事件 构成一次鼠标双击事件:
mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
4、使用绝对坐标
MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 500, 500, 0, 0
模拟键盘输入如下:
void EnterString(const char* text)
{
bool bShift = false;
size_t length = strlen(text);
for(size_t index = 0;index < length;index++)
{
int val = text[index];
if(val >= 97 && val <= 122) //小写a-z
{
val -= 32;
bShift = false;
}
else if(val >= 65 && val <= 90) //大写A-Z
{
bShift = true;
}
else if(val >= 48 && val <= 57) //数字0-9
{
bShift = false;
}
else //特殊符号
{
switch(val)
{
case '`':
val = 192;
bShift = false;
break;
case '~':
val = 192;
bShift = true;
break;
case '!':
val = '1'; //!和1在同一个键盘,使用同一个键盘码,以下相同
bShift = true;
break;
case '@':
val = '2'; //@和2在同一个键盘,使用同一个键盘码,以下相同
bShift = true;
break;
case '#':
val = '3';
bShift = true;
break;
case '$':
val = '4';
bShift = true;
break;
case '%':
val = '5';
bShift = true;
break;
case '^':
val = '6';
bShift = true;
break;
case '&':
val = '7';
bShift = true;
break;
case '*':
val = '8';
bShift = true;
break;
case '(':
val = '9';
bShift = true;
break;
case ')':
val = '0';
bShift = true;
break;
case '-':
val = 189;
bShift = false;
break;
case '=':
val = 187;
bShift = false;
break;
case '_':
val = 189;
bShift = true;
break;
case '+':
val = 187;
bShift = true;
break;
case '[':
val = 219;
bShift = false;
break;
case '{':
val = 219;
bShift = true;
break;
case ']':
val = 221;
bShift = false;
break;
case '}':
val = 221;
bShift = true;
break;
case '\\':
val = 220;
bShift = false;
break;
case '|':
val = 220;
bShift = true;
break;
case ';':
val = 186;
bShift = false;
break;
case ':':
val = 186;
bShift = true;
case '\'':
val = 222;
bShift = false;
break;
case '\"':
val = 222;
bShift = true;
break;
case ',':
val = 188;
bShift = false;
break;
case '<':
val = 188;
bShift = true;
break;
case '.':
val = 190;
bShift = false;
break;
case '>':
val = 190;
bShift = true;
break;
case '/':
val = 191;
bShift = false;
break;
case '?':
val = 191;
bShift = true;
break;
default:
break;
}
}
if(bShift)
keybd_event(VK_SHIFT,0,0,0);
keybd_event(val,0,0,0);
keybd_event(val,0,KEYEVENTF_KEYUP,0);
if(bShift)
keybd_event(VK_SHIFT,0,KEYEVENTF_KEYUP,0);
}
}
1、这里是鼠标左键按下和松开两个事件的组合即一次单击:
mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
2、模拟鼠标右键单击事件:
mouse_event (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 )
3、两次连续的鼠标左键单击事件 构成一次鼠标双击事件:
mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 )
4、使用绝对坐标
MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 500, 500, 0, 0
模拟键盘输入如下:
void EnterString(const char* text)
{
bool bShift = false;
size_t length = strlen(text);
for(size_t index = 0;index < length;index++)
{
int val = text[index];
if(val >= 97 && val <= 122) //小写a-z
{
val -= 32;
bShift = false;
}
else if(val >= 65 && val <= 90) //大写A-Z
{
bShift = true;
}
else if(val >= 48 && val <= 57) //数字0-9
{
bShift = false;
}
else //特殊符号
{
switch(val)
{
case '`':
val = 192;
bShift = false;
break;
case '~':
val = 192;
bShift = true;
break;
case '!':
val = '1'; //!和1在同一个键盘,使用同一个键盘码,以下相同
bShift = true;
break;
case '@':
val = '2'; //@和2在同一个键盘,使用同一个键盘码,以下相同
bShift = true;
break;
case '#':
val = '3';
bShift = true;
break;
case '$':
val = '4';
bShift = true;
break;
case '%':
val = '5';
bShift = true;
break;
case '^':
val = '6';
bShift = true;
break;
case '&':
val = '7';
bShift = true;
break;
case '*':
val = '8';
bShift = true;
break;
case '(':
val = '9';
bShift = true;
break;
case ')':
val = '0';
bShift = true;
break;
case '-':
val = 189;
bShift = false;
break;
case '=':
val = 187;
bShift = false;
break;
case '_':
val = 189;
bShift = true;
break;
case '+':
val = 187;
bShift = true;
break;
case '[':
val = 219;
bShift = false;
break;
case '{':
val = 219;
bShift = true;
break;
case ']':
val = 221;
bShift = false;
break;
case '}':
val = 221;
bShift = true;
break;
case '\\':
val = 220;
bShift = false;
break;
case '|':
val = 220;
bShift = true;
break;
case ';':
val = 186;
bShift = false;
break;
case ':':
val = 186;
bShift = true;
case '\'':
val = 222;
bShift = false;
break;
case '\"':
val = 222;
bShift = true;
break;
case ',':
val = 188;
bShift = false;
break;
case '<':
val = 188;
bShift = true;
break;
case '.':
val = 190;
bShift = false;
break;
case '>':
val = 190;
bShift = true;
break;
case '/':
val = 191;
bShift = false;
break;
case '?':
val = 191;
bShift = true;
break;
default:
break;
}
}
if(bShift)
keybd_event(VK_SHIFT,0,0,0);
keybd_event(val,0,0,0);
keybd_event(val,0,KEYEVENTF_KEYUP,0);
if(bShift)
keybd_event(VK_SHIFT,0,KEYEVENTF_KEYUP,0);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你说的是VC吧?
追问
是的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询