Writing Keyboard Macros in LDPlayer: Commands, Syntax, and Examples
A macro runs a sequence of actions from one key press. You can use macros for repeated clicks, one-key combos, and one-key chat messages. This reference covers how to add a macro button to a game, what each command does, and how to read scr
Before You Start
Prerequisites: LDPlayer installed, with a game running in an instance.; LDPlayer version 3.24 or later, if you want to read coordinates in the Macro editor. Some commands need later versions. See the table below.
Step-by-Step
- Launch your game in the emulator.
- At the top right of the emulator, click Keyboard mapping.
- Drag the Write macro button into the game screen. Its position does not matter.
- Press the keyboard key you want to use for the macro button, right after you drag it.
- Click the pencil icon at the lower-right of the macro button.
- Type your commands in the Macro editor.
- Click Save at the bottom of the Macro editor.
- Click Save in the emulator.
- To read a coordinate, hover over a point in LDPlayer. The value appears at the bottom-left of the Macro editor.
## Overview
A macro runs a sequence of actions from one key press. You can use macros for repeated clicks, one-key combos, and one-key chat messages. This reference covers how to add a macro button to a game, what each command does, and how to read screen coordinates. Commands are typed in the Macro editor.
## Command reference
| Command | Syntax | What it does | | — | — | — | | size | size x1 y1 | Sets the emulator window resolution, for example size 1280 720. Place it before any command that uses coordinates. It still works after you zoom the window, but it stops working if the emulator resolution changes. | | touch | touch x1 y1 time(ms) or touch x1 y1 x2 y2 time(ms) | Clicks one position. With four coordinates, it slides from point A to point B over the set time. Example: touch 100 200 200 200 1000. | | wait | wait time(ms) | Pauses between commands. Example: wait 1000. | | press | press x1 y1 x2 y2 time(ms), then release | Long-presses between two coordinates. The total time is divided among them. In the source example, 5000 ms gives 2500 ms per coordinate. | | press-n | press-n x1 y1 | Clicks n positions together. Example: press-3 with three coordinates. No release command is needed. | | key | key X | Triggers a key mapping you have already set. Use it to build one-key combos. | | text | text your words | Types the words into the chat input box. Pair it with key enter to open the chat box first. | | ondown, onup | ondown … onup | Commands between ondown and onup run when the macro key is pressed. Commands after onup run when it is released. | | loop | loop | Repeats the commands below it while you hold the macro key. To keep the loop running after release, click another application or the desktop while you still hold the key. | | switch-mouse | switch-mouse | Shows or hides the cursor. It works with the Shoot-view button. | | type=mouse-lock | type=mouse-lock | Keeps the mouse inside the emulator window. The source suggests it for MOBA games. | | type=cancel | type=cancel | Cancels a skill cast if you press the macro key while a skill key is held. |
## Examples
- Pressing F triggers three clicks at (800, 600), (900, 600), and (1000, 600).
- Pressing F clicks (800, 600). Releasing F clicks (900, 600).
- A loop repeats its commands for as long as you hold F.
- Pressing 6 casts the E and W skills in turn. The direction follows the mouse.
- For one-key chat, use
key enterto open the chat box, thentextto type your message. - In a 3D game, pair
switch-mousewithondownandonupso the right button stays held while you turn the view. The source sample uses this code:
size 1920 1080
ondown
switch-mouse
onup
switch-mouse
- Click several points at once with
press-n. This example needs version 3.55 or later:
size 1280 720
press-1 855 487
press-2 823 275
press-3 1155 322
press-4 640 440
## Notes
- Enter the
sizecommand again after you change the emulator resolution. The old command stops working. - Put
sizebefore any command that uses coordinates. - Coordinates depend on the game layout and screen size. Read them again if the layout changes.
## Related