pub trait Mouse {
// Required methods
fn button(
&mut self,
button: Button,
direction: Direction,
) -> InputResult<()>;
fn move_mouse(
&mut self,
x: i32,
y: i32,
coordinate: Coordinate,
) -> InputResult<()>;
fn scroll(&mut self, length: i32, axis: Axis) -> InputResult<()>;
fn main_display(&self) -> InputResult<(i32, i32)>;
fn location(&self) -> InputResult<(i32, i32)>;
}展开描述
包含控制鼠标和获取显示屏尺寸的函数。 Enigo 使用笛卡尔坐标系来指定坐标。该坐标系的原点位于当前屏幕的左上角,正值沿坐标轴向下和向右延伸,单位为像素。所有操作系统均使用相同的坐标系。
必需方法§
源代码fn move_mouse(
&mut self,
x: i32,
y: i32,
coordinate: Coordinate,
) -> InputResult<()>
fn move_mouse( &mut self, x: i32, y: i32, coordinate: Coordinate, ) -> InputResult<()>
将鼠标光标移动到指定的 x 和 y 坐标。
你可以指定绝对坐标,或相对于当前位置的相对坐标。
若使用绝对坐标,显示器屏幕左上角为 x=0 y=0。增大 y 坐标使光标下移,增大 x 坐标使光标右移。
若使用相对坐标,x 为正值时鼠标光标向右移动相应像素;为负值时向左移动。y 为正值时光标下移,为负值时光标上移。
§错误
请参考 InputError 的文档以了解在哪些情况下会返回错误。
源代码fn scroll(&mut self, length: i32, axis: Axis) -> InputResult<()>
fn scroll(&mut self, length: i32, axis: Axis) -> InputResult<()>
发送鼠标滚轮事件
§Arguments
axis- The axis to scroll onlength- Number of 15° (click) rotations of the mouse wheel to scroll. How many lines will be scrolled depends on the current setting of the operating system.
对于 Axis::Vertical,正长度值向下滚动,负长度值向上滚动。对于 Axis::Horizontal,正长度值向右滚动,负长度值向左滚动。
§错误
请参考 InputError 的文档以了解在哪些情况下会返回错误。