<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fevents</id>
	<title>EN/documentation/basic guide/events - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fevents"/>
	<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/events&amp;action=history"/>
	<updated>2026-11-11T14:00:52Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/events&amp;diff=16883&amp;oldid=prev</id>
		<title>Sancho: Основной текст</title>
		<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/events&amp;diff=16883&amp;oldid=prev"/>
		<updated>2011-09-06T16:53:59Z</updated>

		<summary type="html">&lt;p&gt;Основной текст&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Events&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}&lt;br /&gt;
&lt;br /&gt;
{{Documentation/BASICGuideTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|ShowPrevPage=block&lt;br /&gt;
|PrevPage=EN/documentation/basic_guide/properties&lt;br /&gt;
|NextPage=EN/documentation/basic_guide/control_elements&lt;br /&gt;
|dial=block&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
&lt;br /&gt;
{{OOo}} dialogs and forms are based on an event-oriented programming model where you can assign '''event handlers''' to the control elements. An event handler runs a predefined procedure when a particular action occurs. You can also edit documents or open databases with event handling as well as access other control elements.&lt;br /&gt;
&lt;br /&gt;
{{OOo}} control elements recognize different types of events that can be triggered in different situations. These event types can be divided into four groups:&lt;br /&gt;
&lt;br /&gt;
* '''Mouse control''': Events that correspond to mouse actions (for example, simple mouse movements or a click on a particular screen location).&lt;br /&gt;
* '''Keyboard control''': Events that are triggered by keyboard strokes.&lt;br /&gt;
* '''Focus modification''': Events that {{OOo}} performs when control elements are activated or deactivated.&lt;br /&gt;
* '''Control element-specific events''': Events that only occur in relation to certain control elements.&lt;br /&gt;
&lt;br /&gt;
When you work with events, make sure that you create the associated dialog in the {{OOo}} development environment and that it contains the required control elements or documents (if you apply the events to a form).&lt;br /&gt;
&lt;br /&gt;
[[Image:documentation_basicguide_dlg_03.gif|none|thumb|500px|The OpenOffice.org Basic development environment]]&lt;br /&gt;
&lt;br /&gt;
The figure above shows the {{OOo}} Basic development environment with a dialog window that contains two list boxes. You can move the data from one list to the other using the buttons between the two list boxes.&lt;br /&gt;
&lt;br /&gt;
If you want to display the layout on screen, then you should create the associated {{OOo}} Basic procedures so that they can be called up by the event handlers. Even though you can use these procedures in any module, it is best to limit their use to two modules. To make your code easier to read, you should assign meaningful names to these procedures. Jumping directly to a general program procedure from a macro can result in unclear code. Instead, to simplify code maintenance and troubleshooting, you should create another procedure to serve as an entry point for event handling - even if it only executes a single call to the target procedure.&lt;br /&gt;
&lt;br /&gt;
The code in the following example moves an entry from the left to the right list box of a dialog.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub cmdSelect_Initiated&lt;br /&gt;
&lt;br /&gt;
   Dim lstEntries As Object&lt;br /&gt;
   Dim lstSelection As Object&lt;br /&gt;
&lt;br /&gt;
   lstEntries = Dlg.getControl(&amp;quot;lstEntries&amp;quot;)&lt;br /&gt;
   lstSelection = Dlg.getControl(&amp;quot;lstSelection&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
   If lstEntries.SelectedItem &amp;gt; 0 Then&lt;br /&gt;
     lstSelection.AddItem(lstEntries.SelectedItem, 0)&lt;br /&gt;
     lstEntries.removeItems(lstEntries.SelectItemPos, 1)&lt;br /&gt;
   Else&lt;br /&gt;
     Beep&lt;br /&gt;
   End If&lt;br /&gt;
&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this procedure was created in {{OOo}} Basic, you can assign it to an event required using the property window of the dialog editor.&lt;br /&gt;
&lt;br /&gt;
[[Image:documentation_basicguide_dlg_02.gif|none|thumb|400px|The Assign Action dialog]]&lt;br /&gt;
&lt;br /&gt;
The Assign Action dialog lists all of the available Events. To assign a macro to an event:&lt;br /&gt;
# Select the event&lt;br /&gt;
# Click '''Macro...'''&lt;br /&gt;
# Browse to and select the macro you want to assign&lt;br /&gt;
# Click OK&lt;br /&gt;
&lt;br /&gt;
== Parameters ==&lt;br /&gt;
&lt;br /&gt;
The occurrence of a particular event is not always enough for an appropriate response. Additional information may be required. For example, to process a mouse click, you may need the screen position where the mouse button was pressed.&lt;br /&gt;
&lt;br /&gt;
In {{OOo}} Basic, you can use object parameters to provide more information about an event to a procedure, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub ProcessEvent(Event As Object)&lt;br /&gt;
 &lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The structure and properties of the &amp;lt;tt&amp;gt;Event&amp;lt;/tt&amp;gt; object depend on the type of event that triggers the procedure call.&lt;br /&gt;
&lt;br /&gt;
Regardless of the type of event, all objects provide access to the relevant control element and its model. The control element can be reached using &amp;lt;tt&amp;gt;Event.Source&amp;lt;/tt&amp;gt; and its model using &amp;lt;tt&amp;gt;Event.Source.Model&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can use these properties to trigger an event within an event handler.&lt;br /&gt;
&lt;br /&gt;
== Mouse Events ==&lt;br /&gt;
&lt;br /&gt;
{{OOo}} Basic recognizes the following mouse events:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;Mouse moved&amp;lt;/tt&amp;gt;:user moves mouse&lt;br /&gt;
;&amp;lt;tt&amp;gt;Mouse moved while key pressed&amp;lt;/tt&amp;gt;:user drags mouse while holding down a key&lt;br /&gt;
;&amp;lt;tt&amp;gt;Mouse button pressed&amp;lt;/tt&amp;gt;:user presses a mouse button&lt;br /&gt;
{{Documentation/Note|This event is also used for notifying requests for a popup context menu on the control. In this case, the member &amp;lt;tt&amp;gt;PopupTrigger&amp;lt;/tt&amp;gt; of the event passed to your macro function will be &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;. In particular, if such a request is made by pressing the right mouse button on the control, the event will be fired twice: once for the popup menu request, and once for the real mouse event. If you are interested in only the mouse click, your macro should ignore all calls where &amp;lt;tt&amp;gt;PopupTrigger&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;.}}&lt;br /&gt;
;&amp;lt;tt&amp;gt;Mouse button released&amp;lt;/tt&amp;gt;:user releases a mouse button&lt;br /&gt;
;&amp;lt;tt&amp;gt;Mouse outside&amp;lt;/tt&amp;gt;:user moves mouse outside of the current window&lt;br /&gt;
&lt;br /&gt;
The structure of the associated event objects is defined in the &amp;lt;idl&amp;gt;com.sun.star.awt.MouseEvent&amp;lt;/idl&amp;gt; structure which provides the following information:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;Buttons (short)&amp;lt;/tt&amp;gt;:button pressed (one or more constants in accordance with &amp;lt;idl&amp;gt;com.sun.star.awt.MouseButton&amp;lt;/idl&amp;gt;)&lt;br /&gt;
;&amp;lt;tt&amp;gt;X (long)&amp;lt;/tt&amp;gt;:X-coordinate of mouse, measured in pixels from the top left corner of the control element&lt;br /&gt;
;&amp;lt;tt&amp;gt;Y (long)&amp;lt;/tt&amp;gt;:Y-coordinate of mouse, measured in pixels from the top left corner of the control element&lt;br /&gt;
;&amp;lt;tt&amp;gt;ClickCount (long)&amp;lt;/tt&amp;gt;:number of clicks associated with the mouse event (if {{OOo}} can respond fast enough, &amp;lt;tt&amp;gt;ClickCount&amp;lt;/tt&amp;gt; is also 1 for a double-click because only an individual event is initiated)&lt;br /&gt;
&lt;br /&gt;
The constants defined in &amp;lt;idl&amp;gt;com.sun.star.awt.MouseButton&amp;lt;/idl&amp;gt; for the mouse buttons are:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;LEFT&amp;lt;/tt&amp;gt;:left mouse button&lt;br /&gt;
;&amp;lt;tt&amp;gt;RIGHT&amp;lt;/tt&amp;gt;:right mouse button&lt;br /&gt;
;&amp;lt;tt&amp;gt;MIDDLE&amp;lt;/tt&amp;gt;:middle mouse button&lt;br /&gt;
&lt;br /&gt;
The following example outputs the mouse position as well as the mouse button that was pressed: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub MouseUp(Event As Object)&lt;br /&gt;
&lt;br /&gt;
   Dim Msg As String&lt;br /&gt;
&lt;br /&gt;
   Msg = &amp;quot;Keys: &amp;quot;&lt;br /&gt;
   If Event.Buttons AND com.sun.star.awt.MouseButton.LEFT Then&lt;br /&gt;
     Msg = Msg &amp;amp; &amp;quot;LEFT &amp;quot;&lt;br /&gt;
   End If&lt;br /&gt;
&lt;br /&gt;
   If Event.Buttons AND com.sun.star.awt.MouseButton.RIGHT Then&lt;br /&gt;
     Msg = Msg &amp;amp; &amp;quot;RIGHT &amp;quot;&lt;br /&gt;
   End If&lt;br /&gt;
&lt;br /&gt;
   If Event.Buttons AND com.sun.star.awt.MouseButton.MIDDLE Then&lt;br /&gt;
     Msg = Msg &amp;amp; &amp;quot;MIDDLE &amp;quot;&lt;br /&gt;
   End If&lt;br /&gt;
&lt;br /&gt;
   Msg = Msg &amp;amp; Chr(13) &amp;amp; &amp;quot;Position: &amp;quot;&lt;br /&gt;
   Msg = Msg &amp;amp; Event.X &amp;amp; &amp;quot;/&amp;quot; &amp;amp; Event.Y&lt;br /&gt;
   MsgBox Msg&lt;br /&gt;
&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{VBAnote|The VBA &amp;lt;tt&amp;gt;Click&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;Doubleclick&amp;lt;/tt&amp;gt; events are not available in {{OOo}} Basic. Instead use the {{OOo}} Basic &amp;lt;tt&amp;gt;MouseUp&amp;lt;/tt&amp;gt; event for the &amp;lt;tt&amp;gt;click&amp;lt;/tt&amp;gt; event and imitate the &amp;lt;tt&amp;gt;Doubleclick&amp;lt;/tt&amp;gt; event by changing the application logic.}}&lt;br /&gt;
&lt;br /&gt;
== Keyboard Events ==&lt;br /&gt;
&lt;br /&gt;
The following keyboard events are available in {{OOo}} Basic:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;Key pressed&amp;lt;/tt&amp;gt;:user presses a key.&lt;br /&gt;
;&amp;lt;tt&amp;gt;Key released&amp;lt;/tt&amp;gt;:user releases a key&lt;br /&gt;
&lt;br /&gt;
Both events relate to logical key actions and not to physical actions. If the user presses several keys to output a single character (for example, to add an accent to a character), then {{OOo}} Basic only creates one event.&lt;br /&gt;
&lt;br /&gt;
A single key action on a modification key, such as the Shift key or the Alt key does not create an independent event.&lt;br /&gt;
&lt;br /&gt;
Information about a pressed key is provided by the event object that {{OOo}} Basic supplies to the procedure for event handling. It contains the following properties:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;KeyCode (short)&amp;lt;/tt&amp;gt;:code of the pressed key (default values in accordance with &amp;lt;idl&amp;gt;com.sun.star.awt.Key&amp;lt;/idl&amp;gt;)&lt;br /&gt;
;&amp;lt;tt&amp;gt;KeyChar (String)&amp;lt;/tt&amp;gt;:character that is entered (taking the modification keys into consideration)&lt;br /&gt;
&lt;br /&gt;
The following example uses the &amp;lt;tt&amp;gt;KeyCode&amp;lt;/tt&amp;gt; property to establish if the Enter key, the Tab key, or one of the other control keys has been pressed. If one of these keys has been pressed, the name of the key is returned, otherwise the character that was typed is returned:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub KeyPressed(Event As Object)&lt;br /&gt;
&lt;br /&gt;
   Dim Msg As String&lt;br /&gt;
&lt;br /&gt;
   Select Case Event.KeyCode&lt;br /&gt;
   Case com.sun.star.awt.Key.RETURN&lt;br /&gt;
     Msg = &amp;quot;Return pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.TAB&lt;br /&gt;
     Msg = &amp;quot;Tab pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.DELETE&lt;br /&gt;
     Msg = &amp;quot;Delete pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.ESCAPE&lt;br /&gt;
     Msg = &amp;quot;Escape pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.DOWN&lt;br /&gt;
     Msg = &amp;quot;Down pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.UP&lt;br /&gt;
     Msg = &amp;quot;Up pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.LEFT&lt;br /&gt;
     Msg = &amp;quot;Left pressed&amp;quot;&lt;br /&gt;
   Case com.sun.star.awt.Key.RIGHT&lt;br /&gt;
     Msg = &amp;quot;Right pressed&amp;quot;&lt;br /&gt;
   Case Else&lt;br /&gt;
     Msg = &amp;quot;Character &amp;quot; &amp;amp; Event.KeyChar &amp;amp; &amp;quot; entered&amp;quot;&lt;br /&gt;
   End Select&lt;br /&gt;
   MsgBox Msg&lt;br /&gt;
&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Information about other keyboard constants can be found in the API Reference under the &amp;lt;idl&amp;gt;com.sun.star.awt.Key&amp;lt;/idl&amp;gt; group of constants.&lt;br /&gt;
&lt;br /&gt;
== Focus Events ==&lt;br /&gt;
&lt;br /&gt;
Focus events indicate if a control element receives or loses focus. You can use these events to, for example, determine if a user has finished processing a control element so that you can update other elements of a dialog. The following focus events are available:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;When receiving focus&amp;lt;/tt&amp;gt;:element receives focus&lt;br /&gt;
;&amp;lt;tt&amp;gt;When losing focus&amp;lt;/tt&amp;gt;:element loses focus&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Event&amp;lt;/tt&amp;gt; objects for the focus events are structured as follows:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;FocusFlags (short)&amp;lt;/tt&amp;gt;:cause of focus change (default value in accordance with &amp;lt;idl&amp;gt;com.sun.star.awt.FocusChangeReason&amp;lt;/idl&amp;gt; )&lt;br /&gt;
;&amp;lt;tt&amp;gt;NextFocus (Object)&amp;lt;/tt&amp;gt;:object that receives focus (only for the &amp;lt;tt&amp;gt;When losing focus&amp;lt;/tt&amp;gt; event)&lt;br /&gt;
;&amp;lt;tt&amp;gt;Temporary (Boolean)&amp;lt;/tt&amp;gt;:the focus is temporarily lost&lt;br /&gt;
&lt;br /&gt;
== Control Element-Specific Events ==&lt;br /&gt;
&lt;br /&gt;
In addition to the preceding events, which are supported by all control elements, there are also some control element-specific events that are only defined for certain control elements. The most important of these events are:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;When Item Changed&amp;lt;/tt&amp;gt;:the value of a control element changes&lt;br /&gt;
;&amp;lt;tt&amp;gt;Item Status Changed&amp;lt;/tt&amp;gt;:the status of a control element changes&lt;br /&gt;
;&amp;lt;tt&amp;gt;Text modified&amp;lt;/tt&amp;gt;:the text of a control element changes&lt;br /&gt;
;&amp;lt;tt&amp;gt;When initiating&amp;lt;/tt&amp;gt;:an action that can be performed when the control element is triggered (for example, a button is pressed)&lt;br /&gt;
&lt;br /&gt;
When you work with events, note that some events, such as the &amp;lt;tt&amp;gt;When initiating&amp;lt;/tt&amp;gt; event, can be initiated each time you click the mouse on some control elements (for example, on radio buttons). No action is performed to check if the status of the control element has actually changed. To avoid such “blind events”, save the old control element value in a global variable, and then check to see if the value has changed when an event is executing.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;When initiating&amp;lt;/tt&amp;gt; event is also noteworthy for the following reasons:&lt;br /&gt;
*This event is initiated by either a key-press or a mouse button. Thus, it provides a consistent interface for users who navigate by mouse or by keyboard.&lt;br /&gt;
*When the &amp;lt;tt&amp;gt;Repeat&amp;lt;/tt&amp;gt; property of a command button is set to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;, this event is the one which is repeatedly sent, as long as the triggering action (key down or mouse-button down) remains in effect. &lt;br /&gt;
&lt;br /&gt;
The properties for the &amp;lt;tt&amp;gt;Item Status Changed&amp;lt;/tt&amp;gt; event are:&lt;br /&gt;
&lt;br /&gt;
;&amp;lt;tt&amp;gt;Selected (long)&amp;lt;/tt&amp;gt;:currently selected entry&lt;br /&gt;
;&amp;lt;tt&amp;gt;Highlighted (long)&amp;lt;/tt&amp;gt;:currently highlighted entry&lt;br /&gt;
;&amp;lt;tt&amp;gt;ItemId (long)&amp;lt;/tt&amp;gt;:ID of entry&lt;br /&gt;
&lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Sancho</name></author>
		
	</entry>
</feed>