古詩詞大全網 - 成語用法 - C語言如何模擬鍵盤輸入?

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]。