16,472
社区成员
发帖
与我相关
我的任务
分享
void CAppTest123Dlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
m_ctrEdit.SetFocus();
INPUT *input = new INPUT[10];
memset(input, 0, sizeof(INPUT)*10);
for(int i=0; i<10; i++)
{
input[i].type = INPUT_KEYBOARD; //设置键盘模式
input[i].ki.dwFlags = KEYEVENTF_UNICODE; //输入UNICODE汉字
input[i].ki.wScan = 0x4e00+i; // 具体的文字
}
SendInput(26, input, sizeof(INPUT));
}
// Execute the keyboard command
void CxxxDlg::SetKBMessage(WORD wMM,UINT nChar,UINT nRepCnt,UINT nFlags)
{
// Create the maximum number of user inputs
std::auto_ptr<INPUT> UserInput(new INPUT[nRepCnt]);
INPUT * pUserInput = UserInput.get();
// Build up the keyboard input
for (UINT iInput = 0;iInput < nRepCnt;++iInput)
{
// Get the keyboard input
INPUT & KeyBoardInput = pUserInput[iInput];
// Set the input type
KeyBoardInput.type = INPUT_KEYBOARD;
// Get the keyboard input structure
KEYBDINPUT & KeyBoard = KeyBoardInput.ki;
// Set the scan code
KeyBoard.wScan = 0;
// Set the ignored fields
KeyBoard.dwExtraInfo = 0;
KeyBoard.time = 0;
// Test for the key being pressed or released
KeyBoard.dwFlags = wMM == WM_KEYDOWN ? 0 : KEYEVENTF_KEYUP;
// Set the character
KeyBoard.wVk = nChar;
}
// Send the user input for the keyboard
SendInput(nRepCnt,pUserInput,sizeof(INPUT));
}