[英]How can I capture Mouse Events (mouseDown and mouseUp) on an NSButton?
This is what I wnat to do and I couldn't yet. 这是我要做的事情,我还没有做。 Hope you can help me.
希望您能够帮助我。
I have a button and a table. 我有一个按钮和一张桌子。 And I want to edit table content when I press this button.
而且我想在按此按钮时编辑表格内容。 When I press my button in a mouseDown event I want to capture that event and, let's say, get the actual time.
当我在mouseDown事件中按下按钮时,我想捕获该事件,并说出实际时间。 And when I release the button in a mouseUp event I want to get que actual time again and update a row in my table.
当我在mouseUp事件中释放按钮时,我想再次获取实际时间并更新表中的一行。
For example: 1- Press button (with out releasing it, capture mouseDown event): get actual time, let's say: 18:10:23. 例如:1-按下按钮(不释放按钮,捕获mouseDown事件):获取实际时间,比方说:18:10:23。 2- Release button (capture mouseUp event): get actual time, let's say: 18:10:33.
2-释放按钮(捕获mouseUp事件):获取实际时间,比方说:18:10:33。 3. Update my table:
3.更新我的表:
------------------------- -------------------------
|_#_|__start__|___end___| ==> |_#_|__start__|___end___|
| 1 |00:00:00 |00:00:00 | | 1 |18:10:23 |18:10:33 |
------------------------- -------------------------
How should I do this? 我应该怎么做? My principal problem is that NSButton doesn't capture both mouseDown and mouseUp event.
我的主要问题是NSButton无法同时捕获mouseDown和mouseUp事件。
In the mouseDown: you fetch events until you see a corresponding mouseUp event. 在mouseDown中:获取事件,直到看到相应的mouseUp事件。
Here's a blog entry with examples. 这是带有示例的博客条目 。
I could solve this 我可以解决这个问题
- (void)awakeFromNib
{
[_myButton sendActionOn:NSLeftMouseDownMask];
}
and using what wil said 并使用威尔说的话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.