元编程参考文档

宏自动化

52 个节点

本页内容 52

激活窗口

函数

Brings the window whose title contains this text, ignoring case, to the front and gives it the keyboard - how a macro switches to another program before sending it keys.

签名
激活窗口(标题: 文本) -> 真否
bool ActivateWindow(string title)

参数

名称类型默认值说明
标题文本—Any part of the title as its title bar reads it: "notepad" finds "Untitled - Notepad".

返回

已激活真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

点击鼠标

函数

Presses and releases a mouse button where the pointer already is.

签名
点击鼠标(按钮: Mouse Button)
void ClickMouse(MacroAutomation.MouseButton button)

参数

名称类型默认值说明
按钮Mouse Button—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

在指定位置点击鼠标

函数

Moves the pointer somewhere and clicks there.

签名
在指定位置点击鼠标(X: 整数, Y: 整数, 按钮: Mouse Button)
void ClickMouseAt(
    int x,
    int y,
    MacroAutomation.MouseButton button)

参数

名称类型默认值说明
X整数—
Y整数—
按钮Mouse Button—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

关闭窗口

函数

Asks a window to close, as its title bar button does. False where nothing happened; the application may still refuse.

签名
关闭窗口(窗口: Desktop Window) -> 真否
bool CloseWindow(DesktopWindow window)

参数

名称类型默认值说明
窗口Desktop Window—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

指挥进程的窗口

函数

Applies one command to every window of a named process.

签名
指挥进程的窗口(进程名称: 文本, 命令: Window Command) -> 整数
int CommandProcessWindows(
    string processName,
    WindowCommand command)

参数

名称类型默认值说明
进程名称文本—
命令Window Command—

返回

结果整数

备注

The count rather than a bool, because "minimise that program" over four windows has three
interesting outcomes and not two: none of them, some of them, all of them.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

双击鼠标

函数

Presses and releases a button twice where the pointer already is.

签名
双击鼠标(按钮: Mouse Button)
void DoubleClickMouse(MacroAutomation.MouseButton button)

参数

名称类型默认值说明
按钮Mouse Button—

备注

Composed from the primitive rather than asked of the platform. Every platform recognises a
double click from two presses inside its own double-click interval, and two presses sent
back to back are always inside it, so a per-platform double click would be three
implementations of a two-line loop - two of them unrunnable here.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

拖动

函数

Presses a button at one point, glides to another, and releases.

签名
拖动
    起点 X: 整数
    起点 Y: 整数
    终点 X: 整数
    终点 Y: 整数
    按钮: Mouse Button
    时长(毫秒): 整数
void Drag(
    int fromX,
    int fromY,
    int toX,
    int toY,
    MacroAutomation.MouseButton button,
    int durationMilliseconds = 300)

参数

名称类型默认值说明
起点 X整数—Where the drag starts.
起点 Y整数—Where the drag starts.
终点 X整数—Where it ends.
终点 Y整数—Where it ends.
按钮Mouse Button—Which button is held.
时长(毫秒)整数300Roughly how long the movement between the two takes.

备注

The package had no drag at all, so its one real caller wrote one: set cursor, button down,
wait 50 ms, set cursor, button up. That works for a list item and fails for anything with a
drag threshold, because the pointer arrives at the destination in a single jump and the
application never sees it move while held.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

沿路径拖动

函数

Presses a button at the first point, glides through every remaining point in order, and releases at the last.

签名
沿路径拖动
    路径: Screen Point 数组
    按钮: Mouse Button
    时长(毫秒): 整数
void DragAlong(
    ScreenPoint[] path,
    MacroAutomation.MouseButton button,
    int durationMilliseconds = 300)

参数

名称类型默认值说明
路径Screen Point 数组—Two or more points. One point presses and releases without moving; none does nothing.
按钮Mouse Button—Which button is held.
时长(毫秒)整数300Roughly how long the whole path takes, divided between its segments by length.

备注

The multi-point form exists because the package's only real caller receives a path from a
language model's computer-use reply and used path[0] and path[1], silently
discarding the rest - so a gesture drawn round a corner was delivered as a straight line
through it.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

沿多条路径拖动

函数

Draws a whole pen path: one drag per pen-down..pen-up mark, in order, with the pen lifted between them.

签名
沿多条路径拖动 -> (已画标记数: 整数, 已取消: 真否)
    标记: IReadOnlyList<Vector2 数组>
    X 偏移: 整数
    Y 偏移: 整数
    按钮: Mouse Button
    每个标记毫秒数: 整数
    标记间隔(毫秒): 整数
    取消键: Key
int DragAlongPaths(
    IReadOnlyList<Vector2[]> marks,
    int offsetX,
    int offsetY,
    MacroAutomation.MouseButton button,
    out bool cancelled,
    int millisecondsPerMark = 400,
    int millisecondsBetweenMarks = 60,
    Key cancelKey = Key.None)

参数

名称类型默认值说明
标记IReadOnlyList<Vector2 数组>—One mark per entry, each the ordered points of a single stroke, in the drawing's own coordinates with y downwards. This is the shape a traceable font's pen path arrives in; nothing here knows about fonts, and a plotter file or a hand-written list of points serves equally.
X 偏移整数—Where the drawing's origin sits on the virtual desktop.
Y 偏移整数—Where the drawing's origin sits on the virtual desktop.
按钮Mouse Button—Which button is held while a mark is drawn.
每个标记毫秒数整数400Roughly how long one mark takes, divided between its segments by length.
标记间隔(毫秒)整数60How long the pen rests, lifted, between one mark and the next.
取消键Key无A key that stops the run. Read between every two steps of the pointer and through every rest, so a tap is noticed whenever it comes; the mark in progress is released where the pointer is, which leaves a shorter stroke and never a line trailing off somewhere else. Key.None means nothing stops it.

返回

已画标记数整数
已取消真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

查找窗口

函数

The first window whose title contains this text, or DesktopWindow.None.

签名
查找窗口(标题片段: 文本) -> Desktop Window
DesktopWindow FindWindow(string titleSubstring)

参数

名称类型默认值说明
标题片段文本—

返回

结果Desktop Window
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

按进程查找窗口

函数

Every window whose owning process has this name, ignoring case and an .exe suffix.

签名
按进程查找窗口(进程名称: 文本) -> Desktop Window 数组
DesktopWindow[] FindWindowsByProcess(string processName)

参数

名称类型默认值说明
进程名称文本—

返回

结果Desktop Window 数组

备注

Above the seam, so "find the window of the program I mean" is written once rather than three
times - two of them on platforms that cannot be run here.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

按标题查找窗口

函数

Every window whose title contains this text, ignoring case.

签名
按标题查找窗口(标题片段: 文本) -> Desktop Window 数组
DesktopWindow[] FindWindowsByTitle(string titleSubstring)

参数

名称类型默认值说明
标题片段文本—

返回

结果Desktop Window 数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

聚焦进程

函数

Brings a named process's first window to the front.

签名
聚焦进程(进程名称: 文本) -> 真否
bool FocusProcess(string processName)

参数

名称类型默认值说明
进程名称文本—

返回

结果真否

备注

The first rather than all of them, because focusing several windows in turn leaves whichever
went last in front and is indistinguishable from focusing only that one.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

聚焦窗口

函数

Brings a window to the front and gives it the keyboard. False where nothing happened.

签名
聚焦窗口(窗口: Desktop Window) -> 真否
bool FocusWindow(DesktopWindow window)

参数

名称类型默认值说明
窗口Desktop Window—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

能否读取按键状态

函数

Whether this machine can be asked what the keyboard is doing, as opposed to only told.

签名
能否读取按键状态() -> 真否
bool CanReadKeyState()

返回

结果真否

备注

Separate from MacroAutomation.IsKeyDown because a caller whose stop condition is a key has to be
able to tell "not pressed" from "cannot see the keyboard": a macro that drives the pointer for
minutes and believes the second is the first is a macro nobody can stop. Windows and macOS can;
X11 can when a display opens; nothing else can.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

是否支持

函数

False where nothing here can emulate input on this machine; every call is then a no-op.

签名
是否支持() -> 真否
bool IsSupported()

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

平台名称

函数

A short name for a status line: "Windows", "X11", "Quartz", "none".

签名
平台名称() -> 文本
string PlatformName()

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

支持情况

函数

How far the backend in force is to be trusted. See DesktopInputEmulation.DesktopInputSupport.

签名
支持情况() -> Desktop Input Support
DesktopInputSupport Support()

返回

结果Desktop Input Support
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取光标位置

函数

Where the pointer is now.

签名
获取光标位置() -> Screen Point
ScreenPoint GetCursor()

返回

结果Screen Point

备注

There was no way to ask this before. The Windows file declared GetCursorPos but left it
private and [Obsolete], so no caller could reach it - and the package's one real
caller has a commented-out SetCursor beside the note that the cursor should not be
moved, which is exactly the case a read-back serves: scroll where the pointer already is.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取指定位置的显示器

函数

Which monitor a coordinate is on, or the primary one where it is on none of them.

签名
获取指定位置的显示器(X: 整数, Y: 整数) -> Display Info
DisplayInfo GetDisplayAt(int x, int y)

参数

名称类型默认值说明
X整数—
Y整数—

返回

结果Display Info
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取显示器

函数

Every monitor, with its place on the virtual desktop and its scale.

签名
获取显示器() -> Display Info 数组
DisplayInfo[] GetDisplays()

返回

结果Display Info 数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取前台窗口

函数

The window with focus, or DesktopWindow.None where nothing has it.

签名
获取前台窗口() -> Desktop Window
DesktopWindow GetForegroundWindow()

返回

结果Desktop Window
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取自身进程名称

函数

This process's own name, so a macro can recognise - and avoid acting on - the windows of the program running it.

签名
获取自身进程名称() -> 文本
string GetOwnProcessName()

返回

结果文本
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取有窗口的进程

函数

The distinct names of every process that owns a window, for a caller offering a list to choose from.

签名
获取有窗口的进程() -> 文本数组
string[] GetProcessesWithWindows()

返回

结果文本数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取虚拟桌面边界

函数

The rectangle every coordinate in this class lives in: the union of every monitor.

签名
获取虚拟桌面边界() -> Screen Rectangle
ScreenRectangle GetVirtualDesktopBounds()

返回

结果Screen Rectangle

备注

Its origin can be negative. That is the whole reason this is a rectangle and not a size, and
the reason the old SM_CXSCREEN / SM_CYSCREEN normalisation could not reach a
second monitor.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取窗口边界

函数

Where the first window of a named process is, as four numbers, and whether it was found at all.

签名
获取窗口边界(进程名称: 文本) -> (已找到: 真否, X: 整数, Y: 整数, 宽度: 整数, 高度: 整数, 最大化: 真否)
bool GetWindowBounds(
    string processName,
    out int x,
    out int y,
    out int width,
    out int height,
    out bool maximized)

参数

名称类型默认值说明
进程名称文本—The owning process, ignoring case and an .exe suffix.

返回

已找到真否
X整数
Y整数
宽度整数
高度整数
最大化真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取窗口

函数

Every top-level window that is on screen and has a title, front-most first where the platform has an order.

签名
获取窗口() -> Desktop Window 数组
DesktopWindow[] GetWindows()

返回

结果Desktop Window 数组
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

获取光标下的窗口

函数

The front-most window whose bounds contain the pointer, or DesktopWindow.None.

签名
获取光标下的窗口() -> Desktop Window
DesktopWindow GetWindowUnderCursor()

返回

结果Desktop Window

备注

A bounds test over the enumeration, which each backend returns in front-to-back order, so the
first hit is the one a click would land on. It is a bounds test and not a hit test: a click
on a rounded corner or a transparent region of the front window would reach whatever is
behind it, and no platform reports that without asking the window itself.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

按键是否按下

函数

Whether a key is physically down right now, whoever has focus.

签名
按键是否按下(键: Key) -> 真否
bool IsKeyDown(Key key)

参数

名称类型默认值说明
键Key—

返回

结果真否

备注

The keyboard's MacroAutomation.GetCursor: this package could drive a keyboard and could not read
one, so a macro had no way to notice a person asking it to stop. It reads the device rather
than a window's message queue, which is what makes it answerable while the process running the
macro is minimised and has no focus - the state such a macro is normally in, since it has just
got out of the way of whatever it is driving.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

最大化前台窗口

函数

Maximises the window that currently has focus.

签名
最大化前台窗口() -> 真否
bool MaximizeForegroundWindow()

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

最大化进程窗口

函数

Maximises every window of a named process. Returns how many.

签名
最大化进程窗口(进程名称: 文本) -> 整数
int MaximizeProcessWindows(string processName)

参数

名称类型默认值说明
进程名称文本—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

最大化窗口

函数

Fills the window's monitor with it. False where nothing happened.

签名
最大化窗口(窗口: Desktop Window) -> 真否
bool MaximizeWindow(DesktopWindow window)

参数

名称类型默认值说明
窗口Desktop Window—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

最小化前台窗口

函数

Iconifies the window that currently has focus.

签名
最小化前台窗口() -> 真否
bool MinimizeForegroundWindow()

返回

结果真否

备注

This is what HideEditor did, under a name that says so. The old name described a
caller's intent rather than the operation - it minimised whatever was in front, whether or not
that was an editor - and it was the package's entire window vocabulary.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

最小化进程窗口

函数

Iconifies every window of a named process. Returns how many.

签名
最小化进程窗口(进程名称: 文本) -> 整数
int MinimizeProcessWindows(string processName)

参数

名称类型默认值说明
进程名称文本—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

最小化窗口

函数

Iconifies a window. False where nothing happened.

签名
最小化窗口(窗口: Desktop Window) -> 真否
bool MinimizeWindow(DesktopWindow window)

参数

名称类型默认值说明
窗口Desktop Window—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

移动光标

函数

Moves the pointer by a delta from wherever it is.

签名
移动光标(X 方向导数阶数: 整数, Y 方向导数阶数: 整数)
void MoveCursor(int dx, int dy)

参数

名称类型默认值说明
X 方向导数阶数整数—
Y 方向导数阶数整数—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

平滑移动光标

函数

Moves the pointer to an absolute coordinate over time, accelerating and decelerating.

签名
平滑移动光标(X: 整数, Y: 整数, 时长(毫秒): 整数)
void MoveCursorSmoothly(
    int x,
    int y,
    int durationMilliseconds = 250)

参数

名称类型默认值说明
X整数—Destination x, in virtual-desktop coordinates.
Y整数—Destination y.
时长(毫秒)整数250Roughly how long the movement should take.

备注

A pointer that teleports is the single most reliable signature of emulated input: some
applications ignore a click whose press arrives in the same input batch as the move that got
there, and hover states, drag thresholds and tooltips never fire at all. The easing is a
smoothstep, so the motion starts and ends slowly, which is also what makes the intermediate
positions land on the widgets a real hand would have crossed.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

按键

函数

Presses and releases a key, optionally holding modifiers while it is pressed.

签名
按键(键: Key, 修饰键: Key Modifiers)
void PressKey(
    Key key,
    KeyModifiers modifiers = KeyModifiers.None)

参数

名称类型默认值说明
键Key—The key to press.
修饰键Key Modifiers无Keys held down for the duration of the press. None by default.

备注

Modifiers are pressed in a fixed order and released in the reverse of it, so a chord leaves
the keyboard exactly as it found it. Releasing in the same order as pressing is how an
emulated chord leaves a modifier stuck down - the failure the package README already
records as a "weird sticky key issue".

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

按组合键

函数

Presses a chord given as keys: every key but the last is held, the last is pressed, and the held ones are released in reverse.

签名
按组合键(键: Key 数组)
void PressKeyCombination(Key[] keys)

参数

名称类型默认值说明
键Key 数组—

备注

This is the shape a language model's computer-use reply arrives in - ["ctrl", "c"] -
and the shape the package could not express. The one real caller looped over the array
calling the old PressKey once per name, which pressed and released Control on its own
and then typed a lower-case "c".

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

还原进程窗口

函数

Brings back every minimised window of a named process, each as it was before it was minimised, and leaves its other windows as they are. Returns how many came back.

签名
还原进程窗口(进程名称: 文本) -> 整数
int RestoreProcessWindows(string processName)

参数

名称类型默认值说明
进程名称文本—

返回

结果整数
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

还原窗口

函数

Puts a minimised or maximised window back to its previous size. False where nothing happened.

签名
还原窗口(窗口: Desktop Window) -> 真否
bool RestoreWindow(DesktopWindow window)

参数

名称类型默认值说明
窗口Desktop Window—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

滚动到位置

函数

Scrolls vertically. Positive scrolls down, as one detent of a wheel.

签名
滚动到位置(垂直滚动量: 整数)
void ScrollAbsolute(int scrollY)

参数

名称类型默认值说明
垂直滚动量整数—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

水平滚动

函数

Scrolls horizontally. Positive scrolls right.

签名
水平滚动(水平滚动量: 整数)
void ScrollHorizontal(int scrollX)

参数

名称类型默认值说明
水平滚动量整数—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

发送文本

函数

Types text into whatever has focus, as characters rather than key positions.

签名
发送文本(文本: 文本, 等待时间(毫秒): 整数)
void SendText(string text, int settleMilliseconds = 0)

参数

名称类型默认值说明
文本文本—The text to type.
等待时间(毫秒)整数0How long to wait afterwards. Zero by default.
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

设置光标位置

函数

Puts the pointer at an absolute virtual-desktop coordinate, immediately.

签名
设置光标位置(X: 整数, Y: 整数)
void SetCursor(int x, int y)

参数

名称类型默认值说明
X整数—
Y整数—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

设置按键状态

函数

Holds a key down, or lets it up, without the other half.

签名
设置按键状态(键: Key, 按下: 真否)
void SetKeyState(Key key, bool pressed)

参数

名称类型默认值说明
键Key—
按下真否—

备注

A caller that takes a key down is responsible for putting it back up. Everything composed in
this class pairs its own presses, which is why nothing here can leave a modifier stuck.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

设置鼠标状态

函数

Presses or releases a mouse button without releasing it again.

签名
设置鼠标状态(按钮: Mouse Button, 按下: 真否)
void SetMouseState(
    MacroAutomation.MouseButton button,
    bool pressed)

参数

名称类型默认值说明
按钮Mouse Button—
按下真否—
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

尝试启用按显示器 DPI 感知

函数

Asks Windows to treat this process as per-monitor DPI aware, so the coordinates here are real pixels.

签名
尝试启用按显示器 DPI 感知() -> 真否
bool TryEnablePerMonitorDpiAwareness()

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

尝试按下指定名称的键

函数

Presses a key named as text, including a chord written as one string: "Enter", "esc", "ctrl+c".

签名
尝试按下指定名称的键(键名: 文本) -> 真否
bool TryPressKeyNamed(string keyName)

参数

名称类型默认值说明
键名文本—

返回

结果真否

备注

The string-taking entry point survives, because the caller that needs one receives key names
from a language model and cannot be given an enum. What has gone is the guessing: the old
method parsed, caught whatever the parse threw, prepended VK_ and parsed again, so an
unrecognised name surfaced as an ArgumentException about a key the caller never wrote.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

尝试按下指定名称的多个键

函数

Presses a chord named as separate strings, as ["ctrl", "shift", "n"].

签名
尝试按下指定名称的多个键(键名: 文本数组) -> 真否
bool TryPressKeysNamed(string[] keyNames)

参数

名称类型默认值说明
键名文本数组—

返回

结果真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

等待

函数

Waits, in milliseconds.

签名
等待(毫秒数: 整数)
void Wait(int milliseconds)

参数

名称类型默认值说明
毫秒数整数—

备注

Through the backend rather than straight to Thread.Sleep, so a test that has installed
a DesktopInputEmulation.RecordingDesktopInput can assert what a macro asked to wait for without
spending it. Its default implementation is Thread.Sleep.

所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化

等待,除非按下某键

函数

Waits, unless a key goes down first - in which case it stops waiting there and says so.

签名
等待,除非按下某键(毫秒数: 整数, 键: Key) -> 真否
bool WaitUnlessKeyDown(int milliseconds, Key key)

参数

名称类型默认值说明
毫秒数整数—The longest it waits.
键Key—The key that cuts the wait short, read from the device as MacroAutomation.IsKeyDown reads it.

返回

按键按下真否
所属发行版
元编程(教育版)元编程(专业版)
可用的图种类
事件 例程 状态机状态
声明于
宏自动化
所属包
桌面自动化