---
name: "Am_Main_Event_Loop"
section: "3"
platform: "linux"
package: "open-amulet-dev"
version: "4.3.1-7.1"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/Am_Initialize"
---

# Am\_Main\_Event\_Loop(3)

Amulet initialization and cleanup

Part of [Am\_Initialize(3)](/Am_Initialize/3.md).

## NAME

Am\_Main\_Event\_Loop, Am\_Exit\_Main\_Event\_Loop, Am\_Initialize, Am\_Cleanup - Amulet initialization and cleanup

## SYNOPSIS

**#include \<amulet.h\>**

**extern void Am\_Initialize ();**

**extern void Am\_Main\_Event\_Loop ();**

**extern void Am\_Exit\_Main\_Event\_Loop ();**

**extern void Am\_Cleanup ();**

## DESCRIPTION

OpenAmulet requires a call to  **Am\_Initialize** before referencing any Opal objects or classes.  This function creates the Opal prototypes and sets up  bookkeeping information in OpenAmulet objects and classes.  Similarly, a call to **Am\_Cleanup** at the end of your program  allows OpenAmulet to destroy the prototypes and classes,  explicitly releasing memory and graphical resources that might otherwise  remain occupied after the program exits.

In order for interactors to perceive input from the mouse and keyboard, the main-event-loop must be running.  This loop constantly checks to see if there is an event, and processes it if there is one. The automatic redrawing of graphics also relies on the main-event-loop.  Exposure events, which occur when one window is uncovered or exposed, cause OpenAmulet to refresh the window by redrawing the objects in the exposed area.

A call to **Am\_Main\_Event\_Loop** should be the second-to-last instruction in your main program, just before **Am\_Cleanup**.  Your program will continue to run until you tell it otherwise.  All OpenAmulet programs running **Am\_Main\_Event\_Loop** can be aborted by pressing the escape sequence, which by default is **META-SHIFT-F1**. Most programs will have a Quit option, in the form of a button or menu item, that calls **Am\_Exit\_Main\_Event\_Loop**, which will cause the main event loop to terminate.

## EXAMPLES

This is a simple Amulet program:

```
   int main (void)
   {
     Am_Initialize ();
     Am_Object my_win = Am_Window.Create ("my_win")
       .Set (Am_LEFT, 20)
       .Set (Am_TOP, 50);
     Am_Screen.Add_Part (my_win);
   // code to add widgets to the window would go here
     Am_Main_Event_Loop ();
     Am_Cleanup ();
     return 0;
   }
```

## SEE ALSO

"OpenAmulet Reference Manual"
