利用Windos API对窗口模拟键盘输入字符
以下为代码
#include <stdio.h>
#include <WINDOWS.H>
int main()
{
POINT curpos;//一个可储存坐标点的结构体变量,x横坐标,y,纵坐标,如curpos.x curpos.y
while(1)
{
GetCursorPos(&curpos);//获取当前鼠标的位置,位置将储存在curpos里。
HWND hWnd = WindowFromPoint(curpos);//根据curpos所指的坐标点获取窗口句柄
SendMessage(hWnd,WM_CHAR,WPARAM('g'),0);//发送一个字符(按键)消息g给当前鼠标所指向的窗口句柄
Sleep(300);//睡眠三百毫秒,相当于等待三分之一秒
}
}