Enhanced event capture with mouse and keyboard

Source: Internet
Author: User

Mouse events have been maintained on the traditional click, dblclick, mouseup, mousedown, and mousemove events, and there has not been much improvement over the years. The drag/drop event corresponds to data transmission rather than mouse operations. Therefore, for a program such as openpainter with mouse and keyboard operations, it is necessary to enhance the event capture of the mouse and keyboard.

In openpainter, I used a class named advancedmouseeventlistner to handle traditional mouse events and process them into complex mouse event information. The most useful one is the comprehensive support for drag and drop. We can see that it provides some enhancement events:

Mouseleftbuttonclick
Mouseleftbuttondown
Mouseleftbuttonup
Mouserightbuttonclick
Mouserightbuttondown
Mouserightbuttonup
Mousemovewithoutdragging
Mousestartdragging
Mousedragging
Mousedraggingfinished

To facilitate processing, it completely separates the left and right key events of the mouse. A series of drag-and-drop related events can make development of drag-and-drop operations very easy. First, when the mouse moves in a non-drag-and-drop State, in addition to the normal mousemove event, the mousemovewithoutdragging event will continue to occur, so as to facilitate the independent processing of the non-drag-and-drop state. When the mouse key is pressed and moved, the mousestartdragging event is triggered, indicating the start of a drag-and-drop operation. During the drag-and-drop process, in addition to the normal mousemove event, the mousedragging event will continue to occur to indicate that this is the movement generated during the drag-and-drop process. When the drag-and-drop operation is complete and the mouse key is released, the mousedraggingfinished event is triggered again.

All these events will pass advancedmouseeventargs-type event data, which contains a lot of data: for example, the dragginganchor attribute indicates the starting point of the drag-and-drop operation; the lastmovedvector attribute indicates the drag-and-drop operation process, the last moving vector. The draggingsize and draggingbounds attributes show the drag-and-drop size and region generated by this drag-and-drop operation. Of course, the isdragging attribute also shows whether the drag-and-drop operation is currently in progress. It must be noted that this information can be obtained not only from event data, but also from advancedmouseeventlistner at any time.

In comparison, keyboard processing is much easier. A keyboard event uses keyboardmonitor to globally capture the main form, and does not generate a new event type as the mouse listener does. Instead, it is a more friendly description of the keyboard status. For example, you can use the pressedkeys attribute to enumerate all the keys that have been pressed (you cannot enumerate keys A and B at the same time through traditional events ); you can access isshiftpressed, isctrlpressed, and isaltpressed to easily check the modification key status. You can also view the pressing status of any key using the ispressed method. Another difference from traditional events is that if you press the Space key, a key event is generated continuously. However, in openpainter, each key may be a modifier key, it should be processed like shift and other keys. Therefore, keyboardmonitor filters all key events. No matter how long it is pressed, any key generates only one group of events.

Note: advancedmouseeventlistner was basically implemented at the end of last year and has been enhanced this month. Keyboardmonitor was completed on 2008/7/16.

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.