2012-10-04 56 views
0

我已經創建了一個Kinect的點擊功能,而不使用任何手勢..它的簡單和它的工作原理..但是我希望功能等待..我的計數器似乎沒有工作。 。我想要做的是..如果我的手在按鈕上讓我們說超過3秒..然後返回true ..任何方法來做到這一點?計數器似乎沒有工作添加一個定時器到Kinect點擊功能C#

public bool KinectClick(int x,int y) 
      { 

       if ((x >= position.X && x <= position.X +position.Width) && (y >= position.Y && y <= position.Y + position.Height)) 
       { 
       // time.Start(); 
        int counter = 0; 

        while (true) 
        { 
         counter++; 

         if (counter >= 8000) 
         { 
          return true; 
          counter = 0; 


         } 
        } 

       } 

回答

1

我使用DispatcherTimer來完成你正在嘗試做的相同的事情。一個簡單的形式可以是這個樣子:

private DispatcherTimer hitTestTimer = new DispatcherTimer(); 
private int timerCount = 5; 

public MyConstructor() { 
    hitTestTimer.Tick += OnHitTestTimerTick; 
    hitTestTimer.Interval = new TimeSpan(0, 0, 1); 
} 

private void OnHitTestTimerTick(object sender, EventArgs e) 
{ 
    if (timerCount > 1) 
    { 
    timerCount--; 
    } 
    else 
    { 
    // CLICK! 
    } 
} 

您可以添加切換的標誌,當你第一次進入你的對象,並檢查覈實,如果您有(或沒有)離開了對象,因爲最後的計時器蜱。

相關問題