Cocoa - 当鼠标不拖动时如何获取鼠标按下事件?

发布于 2024-09-08 01:22:33 字数 302 浏览 2 评论 0原文

可可,Mac OS X 10.6。

我的应用程序(游戏)需要重复确定鼠标是否在视图内按下,即使鼠标位置没有改变。

问题:

  • mouseDown 只会在第一次按下鼠标时被调用。如果此时鼠标移动,则不会调用mouseDragged,并且不会生成更多mouseDown事件。

问题:如何确定在初始(也是唯一)mouseDown 事件之后鼠标仍然处于按下状态?

谢谢。

Cocoa, Mac OS X 10.6.

My app (a game) needs to determine if the mouse is down within a view, repeatedly, even if the mouse position doesn't change.

The problem:

  • mouseDown will only be called the first time the mouse is pressed and held down. If the mouse is not moved at this point, mouseDragged is not called, and no more mouseDown events are generated.

Question: how do I determine that the mouse is still down after that initial (and only) mouseDown event?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

‘画卷フ 2024-09-15 01:22:33

如果您需要在鼠标按下时定期执行某些操作,请使用 mouseDown: 创建一个重复的 计时器,并让 mouseUp: 将其拆除。

If you need to do something periodically while the mouse is down, have mouseDown: create a repeating timer, and have mouseUp: tear it down.

能怎样 2024-09-15 01:22:33

如果您只想知道鼠标是否按下,请在 mouseDown:mouseUp: 中设置一个 BOOL 变量。

如果您想在鼠标按下时继续执行某些操作,可以输入鼠标跟踪循环,如下所述:鼠标跟踪循环方法 基本上,您会循环直到找到鼠标松开事件,并且你可以在循环中做任何你想做的事情。您必须使用 nextEventMatchingMask:untilDate:inMode:dequeue: 而不是 nextEventMatchingMask: 并将 untilDate 设置为较短的值。

If you just want to know whether the mouse is down or not, set a BOOL variable in mouseDown: and mouseUp:.

If you want to keep doing something while the mouse is down, you can enter a mouse tracking loop as explained here: The Mouse-Tracking Loop Approach Basically you loop until you find the mouse up event, and you can do whatever you want in the loop. You will have to use nextEventMatchingMask:untilDate:inMode:dequeue: instead of nextEventMatchingMask: and set the untilDate to something short.

浅沫记忆 2024-09-15 01:22:33

CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft));

这就是您在 64 位上所追求的。 (好吧晚了4年)。

// 莫兹拉...

     1.30  #ifdef XP_MACOSX
     1.31 -  // hacky OS call to ensure that we don't show a context menu when the user
     1.32 -  // let go of the mouse already, after a long, cpu-hogging operation prevented
     1.33 +  // Hack to ensure that we don't show a context menu when the user
     1.34 +  // let go of the mouse after a long cpu-hogging operation prevented
     1.35    // us from handling any OS events. See bug 117589.
     1.36 -  if (!::StillDown())
     1.37 +  if (!CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft))
    1.38      return;
    1.39  #endif

CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft));

is what you are after on 64 bit. (ok 4 years late).

// mozzilla...

     1.30  #ifdef XP_MACOSX
     1.31 -  // hacky OS call to ensure that we don't show a context menu when the user
     1.32 -  // let go of the mouse already, after a long, cpu-hogging operation prevented
     1.33 +  // Hack to ensure that we don't show a context menu when the user
     1.34 +  // let go of the mouse after a long cpu-hogging operation prevented
     1.35    // us from handling any OS events. See bug 117589.
     1.36 -  if (!::StillDown())
     1.37 +  if (!CGEventSourceButtonState(kCGEventSourceStateCombinedSessionState, kCGMouseButtonLeft))
    1.38      return;
    1.39  #endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文