21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Events<br />

A single key action on a modification key, such as the Shift key or the Alt key does not create an independent<br />

event.<br />

Information about a pressed key is provided by the event object that <strong>OpenOffice</strong>.<strong>org</strong> Basic supplies to the<br />

procedure for event handling. It contains the following properties:<br />

KeyCode (short)<br />

code of the pressed key (default values in accordance with com.sun.star.awt.Key)<br />

KeyChar (String)<br />

character that is entered (taking the modification keys into consideration)<br />

The following example uses the KeyCode property to establish if the Enter key, the Tab key, or one of the other<br />

control keys has been pressed. If one of these keys has been pressed, the name of the key is returned, otherwise<br />

the character that was typed is returned:<br />

Sub KeyPressed(Event As Object)<br />

Dim Msg As String<br />

Select Case Event.KeyCode<br />

Case com.sun.star.awt.Key.RETURN<br />

Msg = "Return pressed"<br />

Case com.sun.star.awt.Key.TAB<br />

Msg = "Tab pressed"<br />

Case com.sun.star.awt.Key.DELETE<br />

Msg = "Delete pressed"<br />

Case com.sun.star.awt.Key.ESCAPE<br />

Msg = "Escape pressed"<br />

Case com.sun.star.awt.Key.DOWN<br />

Msg = "Down pressed"<br />

Case com.sun.star.awt.Key.UP<br />

Msg = "Up pressed"<br />

Case com.sun.star.awt.Key.LEFT<br />

Msg = "Left pressed"<br />

Case com.sun.star.awt.Key.RIGHT<br />

Msg = "Right pressed"<br />

Case Else<br />

Msg = "Character " & Event.KeyChar & " entered"<br />

End Select<br />

MsgBox Msg<br />

End Sub<br />

Information about other keyboard constants can be found in the API Reference under the com.sun.star.awt.Key<br />

group of constants.<br />

Focus Events<br />

Focus events indicate if a control element receives or loses focus. You can use these events to, for example,<br />

determine if a user has finished processing a control element so that you can update other elements of a dialog.<br />

The following focus events are available:<br />

When receiving focus<br />

element receives focus<br />

When losing focus<br />

element loses focus<br />

The Event objects for the focus events are structured as follows:<br />

FocusFlags (short)<br />

cause of focus change (default value in accordance with com.sun.star.awt.FocusChangeReason)<br />

NextFocus (Object)<br />

object that receives focus (only for the When losing focus event)<br />

160 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!