C语言如何模拟键盘输入?

C语言模拟键盘代码如下:

intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRszCmdLine,intiCmdShow)

{

MSGmsg;

if(!MyRegisterClass(hInstance))

{

returnFALSE;

}

if(!InitInstance(hInstance,iCmdShow))

{

returnFALSE;

}

while(GetMessage(&msg,NULL,0,0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

returnmsg.wParam;

}

//函数:ShowKey

//作用:实现在窗口中显示按键信息

voidShowKey(HWNDhwnd,intiType,char*szMessage,WPARAMwParam,LPARAMlParam)

{

staticchar*szFormat[2]={"%-14s%3d%c%6u%4d%5s%5s%6s%6s",

"%-14s%3d%c%6u%4d%5s%5s%6s%6s"};

charszBuffer[80];

HDChdc;

ScrollWindowEx(hwnd,0,-yChar,&rc,&rc,NULL,NULL,SW_INVALIDATE);

hdc=GetDC(hwnd);

SelectObject(hdc,GetStockObject(SYSTEM_FIXED_FONT));

TextOut(hdc,

xChar,

rc.bottom-yChar,

szBuffer,

wsprintfszBuffer,

szFormat[iType]。