开发者

c++ send ENTER keyboard_event with Timer as Guard

std::cout<<"SendKeyBoardEvent "<<keyBEventType<<endl;
// Simulate a key press
  Sleep(200); //in

if (!strcmp(keyBEventType,"ENTER"))
{
    // ENTER key down
      keybd_event(VK_RETURN,0x9C,0,0);
    // ENTER key up
     keybd_event(VK_RETURN,0x9C, 0,0);
}

When I run this code from my tool, I must use two keys arrow down and and enter or any other two keys combo except ALT-ENTER. I had used KEY_UP and CONTROL. anyone see my problem here? I appreciate for your help.

SOLUTION for getch() with Timer as Guard In-Case FTP Transferred(SpecialClient) Forever

Either Timer Expire or User Enter Key first

void waitBoostSleep(int seconds) 
{ 
  boost::this_thread::sleep(boost::posix_time::se开发者_如何学运维conds(seconds)); 
} 

int waitTime(int sec)
{
  waitBoostSleep(sec);
  a->SendKeyBoardEvent("ENTER");
  std::cout<<"TimerExpired after "<<sec<<endl;
  return 0;
}

int StopSicFTPRingBuffer (int TimeInSeconds)
{
boost::thread t66(&waitTime,TimeInSeconds);
if  (getch() == 13)
{
    a->SendKeyBoardEvent("ENTER");
    return 1;
}
t66.join();

return 0;
}

From Main Program

boost::thread t77(&StopSicFTPRingBuffer,45);
system(SicFTPR.str().c_str());                      
t77.join();

Sytem will call a special ftp client where it can be interrupted by user with ENTER return.

In-case, someone like me needs this kind of requirements. It worked perfectly for me. I had set 45 seconds, if the timer expired, then the ENTER key will execute automatic to stop FTP transferred. If user hit ENTER key first before the timer expired, then FTP transferred will be stopped.


You weren't doing a keyup, you were doing two key downs. Try this:

// ENTER key down
keybd_event(VK_RETURN, 0x9C, 0, 0);

// ENTER key up
keybd_event(VK_RETURN, 0x9C, KEYEVENTF_KEYUP, 0);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜