To judge the mouse double button press (with keyboard key combination)

Source: Internet
Author: User

To help you check the API, there are some words you may not pay attention to see:
The button mask returned by Inputevent.getmodifiers () reflects only the button this is changed state f all buttons. (Note:due to overlap in the same values of Alt_mask/button2_mask and meta_mask/button3_mask, this isn't always true for mouse Events involving modifier keys). To get the state of all buttons and modifier keys, use Inputevent.getmodifiersex ().

Inputevent.getmodifiers () only reflects the change state of a single key, and if you want to obtain the state of the key combination, you must use Inputevent.getmodifiersex ().

The following code I have tested, can be judged:
Gtext.addmouselistener (New Mouseadapter ()
{
public void mousepressed (MouseEvent e)
{

if (E.getbutton () ==e.button1)
Glabel.settext ("Button1"); Judge left Key

if (E.getbutton () ==e.button3)
Glabel.settext ("Button3")/Right Key

if (e.getmodifiersex () = = (E.button3_down_mask + e.button1_down_mask))
Glabel.settext ("bt1+bt3!"); To determine the right and left key pressed at the same time

if (e.getmodifiersex () = = (E.shift_down_mask + e.button1_down_mask))
Glabel.settext ("shift+bt1");//shift+ left arrow
//............... Other similarities, modifying constant values can be
}

}
);



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.