Input Data

Moonlight will send all user inputs via the control stream.

General format of an `INPUT_DATA` message
Figure 1. General format of an INPUT_DATA message

The first 4 bytes (big endian) following the header of a packet of type INPUT_DATA indicate the size of the message, which varies depending on the input type. The next 4 bytes (little endian) specify the input type, which can be any of the values in the following table.

Input type name Value

MOUSE_MOVE_REL

0x00000007

MOUSE_MOVE_ABS

0x00000005

MOUSE_BUTTON_DOWN

0x00000008

MOUSE_BUTTON_UP

0x00000009

KEY_DOWN

0x00000003

KEY_UP

0x00000004

MOUSE_SCROLL

0x0000000A

MOUSE_HSCROLL

0x55000001

TOUCH

0x55000002

PEN

0x55000003

CONTROLLER_MULTI

0x0000000C

CONTROLLER_ARRIVAL

0x55000004

CONTROLLER_TOUCH

0x55000005

CONTROLLER_MOTION

0x55000006

CONTROLLER_BATTERY

0x55000007

HAPTICS

0x0000000D

UTF8_TEXT

0x00000017

Mouse: relative move

Moonlight will send mouse relative coordinates when the option "Optimize mouse for remote desktop instead of games" is turned OFF.

The full format of a `MOUSE_MOVE_REL` packet
Figure 2. The full format of a MOUSE_MOVE_REL packet

Delta X and Delta Y defines the relative movement that the mouse must perform.

Delta X and Delta Y are encoded as big endian.

Mouse: absolute move

Moonlight will send mouse absolute coordinates when the option "Optimize mouse for remote desktop instead of games" is turned ON.

The full format of a `MOUSE_MOVE_ABS` packet
Figure 3. The full format of a MOUSE_MOVE_ABS packet

In order to define an absolute position Moonlight will send both:

  • width, height which represent the size of the viewport on the client side

  • X,Y are the absolute coordinates of the mouse on the client side

X, Y, width and height are encoded as big endian.

Mouse: button

The full format of a `MOUSE_BUTTON_DOWN` or `MOUSE_BUTTON_UP` packet
Figure 4. The full format of a MOUSE_BUTTON_DOWN or MOUSE_BUTTON_UP packet

Action can have the following values:

Action data Meaning

0x09

Button released

0x08

Button pressed

Button can have the following values:

Button data Meaning

1

Button left

2

Button middle

3

Button right

4

Button side

5

Button extra

Keyboard

The full format of a `KEY_DOWN` or `KEY_UP` packet
Figure 5. The full format of a KEY_DOWN or KEY_UP packet

Action can have the following values:

Action data Meaning

0x04

Button released

0x03

Button pressed

What’s modifiers?

Key code represent the corresponding keyboard code of the pressed input, see the following table:

Moonlight code Keyboard button

0x08

BACKSPACE

0x09

TAB

0x0C

CLEAR

0x0D

ENTER

0x10

LEFTSHIFT

0x11

LEFTCTRL

0x12

LEFTALT

0x13

PAUSE

0x14

CAPSLOCK

0x15

KATAKANAHIRAGANA

0x16

HANGEUL

0x17

HANJA

0x19

KATAKANA

0x1B

ESC

0x20

SPACE

0x21

PAGEUP

0x22

PAGEDOWN

0x23

END

0x24

HOME

0x25

LEFT

0x26

UP

0x27

RIGHT

0x28

DOWN

0x29

SELECT

0x2A

PRINT

0x2C

SYSRQ

0x2D

INSERT

0x2E

DELETE

0x2F

HELP

0x30

0

0x31

1

0x32

2

0x33

3

0x34

4

0x35

5

0x36

6

0x37

7

0x38

8

0x39

9

0x41

A

0x42

B

0x43

C

0x44

D

0x45

E

0x46

F

0x47

G

0x48

H

0x49

I

0x4A

J

0x4B

K

0x4C

L

0x4D

M

0x4E

N

0x4F

O

0x50

P

0x51

Q

0x52

R

0x53

S

0x54

T

0x55

U

0x56

V

0x57

W

0x58

X

0x59

Y

0x5A

Z

0x5B

LEFTMETA

0x5C

RIGHTMETA

0x5F

SLEEP

0x60

NUMPAD 0

0x61

NUMPAD 1

0x62

NUMPAD 2

0x63

NUMPAD 3

0x64

NUMPAD 4

0x65

NUMPAD 5

0x66

NUMPAD 6

0x67

NUMPAD 7

0x68

NUMPAD 8

0x69

NUMPAD 9

0x6A

NUMPAD ASTERISK

x6B

NUMPAD PLUS

0x6C

NUMPAD COMMA

0x6D

NUMPAD MINUS

0x6E

NUMPAD DOT

0x6F

NUMPAD SLASH

0x70

F1

0x71

F2

0x72

F3

0x73

F4

0x74

F5

0x75

F6

0x76

F7

0x77

F8

0x78

F9

0x79

F10

0x7A

F11

0x7B

F12

0x90

NUMLOCK

0x91

SCROLLLOCK

0xA0

LEFTSHIFT

0xA1

RIGHTSHIFT

0xA2

LEFTCTRL

0xA3

RIGHTCTRL

0xA4

LEFTALT

0xA5

RIGHTALT

0xBA

SEMICOLON

0xBB

EQUAL

0xBC

COMMA

0xBD

MINUS

0xBE

DOT

0xBF

SLASH

0xC0

GRAVE

0xDB

LEFTBRACE

0xDC

BACKSLASH

0xDD

RIGHTBRACE

0xDE

APOSTROPHE

0xE2

102ND

Mouse scroll

The full format of a `MOUSE_SCROLL` packet
Figure 6. The full format of a MOUSE_SCROLL packet

We only use amount 1 to determine the amount of scroll to be applied.

What’s amount 2?

Mouse horizontal scroll

The full format of a `MOUSE_HSCROLL` packet
Figure 7. The full format of a MOUSE_HSCROLL packet

Touch

new in Moonlight 5.0.0

Pen

new in Moonlight 5.0.0

Controller

Controller arrival

new in Moonlight 5.0.0

Sent when a new connector has been plugged, it’ll specify the supported capabilities and the specific type of controller to be emulated.

The full format of a `CONTROLLER_ARRIVAL` packet
Figure 8. The full format of a CONTROLLER_ARRIVAL packet

Where controller type can be:

Moonlight code Description

Unknown

0x00

XBOX

0x01

PS

0x02

Nintendo

0x03

And the capabilities is a bitfield with the followings options:

Moonlight code Description

Analog triggers

0x01

Rumble

0x02

Trigger Rumble

0x04

Touchpad

0x08

Accelerometer

0x10

Gyro

0x20

Battery

0x40

RGB LED

0x80

Controller multi

Since Moonlight 5.0.0 the format has been slightly changed (without breaking the legacy format)
The legacy format of a `CONTROLLER_MULTI` packet
Figure 9. The legacy format of a CONTROLLER_MULTI packet
Legacy format
The legacy format of a `CONTROLLER_MULTI` packet
Figure 10. The legacy format of a CONTROLLER_MULTI packet

LT and RT refer to the left and right triggers, respectively. Left X and the following fields refer to the values of the left and right sticks.

Active mask

The active mask represent a bitfield with bits set for each controller present. If you combine this with the ctrl # (controller number) you can detect when a controller has been unplugged.

An active mask of 0x0 and a controller number of 0x1 means that the first controller has been unplugged.

Button flags

The buttons element encodes the currently pressed buttons in the joypad.

In order to get the new added buttons you have to combine btn flags and btn flags 2 so that

(button_flags | (button_flags2 << 16))
Button type Flag (HEX)

DPAD_UP

0x0001

DPAD_DOWN

0x0002

DPAD_LEFT

0x0004

DPAD_RIGHT

0x0008

START

0x0010

BACK

0x0020

HOME

0x0400

LEFT_STICK

0x0040

RIGHT_STICK

0x0080

LEFT_BUTTON

0x0100

RIGHT_BUTTON

0x0200

A

0x1000

B

0x2000

X

0x4000

Y

0x8000

SPECIAL_FLAG

0x0400

PADDLE 1

0x010000

PADDLE 2

0x020000

PADDLE 3

0x040000

PADDLE 4

0x080000

Touchpad

0x100000

MISC

0x200000

If more than one button is being pressed at the same time button_flag will contain the sum of both values.

When pressing  kbd:[A] and  kbd:[X] `button_flag` contains `0x0050` that `5` decodes as follows:
Figure 11. When pressing A and X button_flag contains 0x0050 that 5 decodes as follows:
The full format of the `button_flag` binary encoding
Figure 12. The full format of the button_flag binary encoding

Controller Touch

new in Moonlight 5.0.0

Controller Motion

new in Moonlight 5.0.0

Controller Battery

new in Moonlight 5.0.0