Skip to main content
Version: next

Screen Power Mode

Turn on or off the device screen.

Different from injecting a power key event, this command only affects the physical screen, it doesn't lock the device.

If cleanup: true (the default value) is set in the ScrcpyOptions, Scrcpy server will restore the screen state to Normal on exit. Pressing the physical power button twice usually turns the screen back on.

Caveats

  • On some LCD screens, turning off the screen only turns off the backlight, the screen is still visible under strong light.
  • Some in-display fingerprint sensors use the screen to illuminate the finger, turning off the screen will cause them to stop working.
  • Most apps are unaware of the screen state, but some apps may behave differently when the screen is off, it has been reported that:
    • Chrome for Android might not respond to touch events
    • Xiaomi HyperOS system UI loses all blur effects

Options

interface ScrcpySetDisplayPowerControlMessage {
on: boolean;
}
  • on: The screen power mode. Use AndroidScreenPowerMode.Off (0) to turn off the screen, or AndroidScreenPowerMode.Normal (2) to set screen to normal power mode.(until v2.7) Whether to turn the screen on (true) or off (false).(since v3.0)

Changelog

v1.15

  • mode field accepts AndroidScreenPowerMode enum with values Off (0) and Normal (2).

v3.0

  • Breaking: mode field replaced with on boolean parameter. true is equivalent to AndroidScreenPowerMode.Normal, false is equivalent to AndroidScreenPowerMode.Off.

Usage

import { AndroidScreenPowerMode } from "@yume-chan/scrcpy";

// Using `ScrcpyControlMessageSerializer`
const message: Uint8Array = serializer.setDisplayPower(AndroidScreenPowerMode.Normal);

// Using `ScrcpyControlMessageWriter`
await writer.setDisplayPower(AndroidScreenPowerMode.Normal);

// Using `AdbScrcpyClient`
await client.controller!.setDisplayPower(AndroidScreenPowerMode.Normal);
info

Since Scrcpy v3.0, the AndroidScreenPowerMode enum is no longer used. Use true for normal mode and false for off mode.

// Since v3.0
await writer.setDisplayPower(true); // Turn screen on
await writer.setDisplayPower(false); // Turn screen off