GWT:处理标签上的多个事件
当用户按住某个键(Ctrl)然后同时单击鼠标按钮(Ctrl + 鼠标单击)时,我想处理标签上的事件,例如打开某个窗口等... 我怎样才能在 GWT 中做到这一点?我应该添加两个处理程序还是可以使用一个处理程序?
谢谢。
阿尔
I want handle events on a Label when user holds down some key (Ctrl) and then clicks the mouse button together (Ctrl + mouse click), like open some window etc...
How could i do that in GWT? Should i get add two handlers or can do it with one?
thank you.
al
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在单击处理程序中,您可以检查事件触发时是否按下了 Ctrl 键,请参阅下面的示例。您可能还想检查用户单击的特定鼠标按钮。我还将其添加到示例中:
或者对于旧版本的 GWT,而不是
event.isControlKeyDown
使用event.getNativeEvent().getCtrlKey()
,它返回一个布尔值如果在触发此事件时按下控制键,则值为 true。In your click handler you can check if the Ctrl key is pressed when the event was fired, see example below. You also might want to check for the specific mouse button the user clicked on. I've also added that to the example:
Or for older version of GWT instead of
event.isControlKeyDown
useevent.getNativeEvent().getCtrlKey()
, which returns a boolean value true if the control key is pressed when this event is fired.编辑:此代码有错误,请查看 Hilbrand 的答案
说实话,我不认为您可以用 1 或 2 个处理程序来完成它。我认为你需要 3 个处理程序。
一个重置 KeyDownHandler 中布尔值的 KeyUpHandler
Edit: this code is buggy, please look at Hilbrand's answer
To be honest, I don't think you can do it with 1 or 2 handlers. I think you would need 3 handler.
A KeyUpHandler that resets the value of the boolean in the KeyDownHandler