How to implement mouse_event() to work continuously in MFC?

别来无恙 提交于 2019-12-13 08:45:11

问题


I am trying to make a MFC Program using Myo.

I made several combo box control for each gesture.

This is my plan.


When I select an option of combo box, It should work as a real mouse.

(e.g. : If I choose option(Left Click), it should allow me to do Left click when I take a pose "Fist" && Myo is in unlock state.

void CMyoControllerView::OnCbnSelchangeComboFist() {
   int nIndex = m_combo_Fist.GetCurSel();

   if(nIndex == 0) {// Left Click
     if(collector.isUnlocked == true && collector.currentPose == myo::Pose::fist) { 
        mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, NULL);
        mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, NULL);
      }
   }
}

However, this code only affects mouse just when I change the option(ONLY ONE TIME!).

I know that I should not put this code in control event code. The problem is that I have no idea where should I put it.

I want to make this function working continuously until I finish this program.

(Like a thread.. I have five combo box and each has different mouse event. All five function should be working together.)

Please give me some advices. Thank you.


回答1:


Create a queue of actions. Have the combobox handler put a click action into the queue. Use a separate timer or thread to process actions that are in the queue. If an action needs to be repeated, put it back in the queue after it has finished.



来源:https://stackoverflow.com/questions/30449209/how-to-implement-mouse-event-to-work-continuously-in-mfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!