Your control can capture and process standard events before they are sent to the host application. The two most common types of interactions are mouse and keyboard events.
For more information, see:
The Control class in WFC provides for most of the mouse events that you need. These include mouseMove, mouseUp, mouseDown, mouseWheel, mouseEnter, and mouseLeave. In addition, you can optionally receive the click and doubleClick events.
To receive mouse events in your control, you can override the event you want. To pass the mouse event through to the host application, call the superclass' corresponding event method.
The following example illustrates how you can override the mouseMove event. The handler indirectly displays the location of the mouse, which is available in the x and y properties of the MouseEvent object passed to the handler:
protected void onMouseMove( MouseEvent e){
String sMsg = "" + e.x + ", " + e.y;
this.setText(sMsg);
invalidate(); // Repaint control when property changes
super.onMouseMove( e ); // to make it visible in the host
}
The standard key events exposed are keyUp, keyDown, and keyPress. These events will be triggered for both normal keys and system keys (for example, F1 through F12).
All keyboard input in WFC is done using Unicode character data. When running under an operating system that doesn’t support Unicode messages (like Windows 95) the WFC framework will automatically perform the needed message filtering to generate Unicode events.
The following example illustrates how you can capture keyboard events within a control. The overridden onKeyUp method here filters out numeric characters before passing the event to the host application:
protected void onKeyUp( KeyEvent e){
if(e.keydata < Key.D0 && e.keyData > Key.D9){
super.onKeyUp( e );
invalidate(); // Repaint control when property changes
}
}