# OpenScreen

`com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen`

**Since:** 1.2.7

**Cancellable:** No. Calling `event.cancel()` throws `UnsupportedOperationException`.

Fires when the client's current screen changes, including when a screen is closed. The event
is dispatched after the screen field is assigned. Reassigning the current screen does not fire
it. On close, both [screen](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen_screen) and [screenName](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen_screenName) are `null`. Container screens
have a separate event that can be cancelled:  
[EventOpenContainer](../inventory/EventOpenContainer.md).  
```js
JsMacros.on("OpenScreen", JavaWrapper.methodToJava(function (event) {
  if (event.screenName === null) {
    Chat.log("A screen was closed");  
  } else {
    Chat.log(`Opened ${event.screenName}`);  
  }
}))
```

## Constructors

### new EventOpenScreen {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen_constructor-Screen-}

```js
new EventOpenScreen(Screen screen)
```

Captures the supplied screen and its display name when constructing the event; this does
not open or close a screen. A `null` screen sets both event fields to `null`.  
A non-null screen must implement [IScreen](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IScreen.md), or the cast fails with
[ClassCastException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/ClassCastException.html).

**Parameters:**
- `screen`: the Minecraft screen to capture, or `null` when closing a screen

## Fields

### screen {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen_screen}

```js
screen: IScreen
```

The newly assigned screen, wrapped as an [IScreen](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IScreen.md); `null` when a screen is
closed. Its class name is available from
[IScreen.getScreenClassName()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IScreen.md#com.jsmacrosce.jsmacros.client.api.classes.render.IScreen_getScreenClassName-).

### screenName {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen_screenName}

```js
screenName: String
```

A display name for the screen: container screens use names assigned by JsMacros, while
other screens use their title or `"unknown"` when the title is empty. This is not a
stable identifier. `null` when a screen is closed.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventOpenScreen_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the event name and captured screen name, in the
form `eventName:{"screenName": "name"}`. A null screen name is formatted as the
literal `null`; this is not JSON serialization and the screen itself is omitted.

**Returns:** the event name and captured screen name in diagnostic form
