跳到主要内容

Mouse

搜索

trait Mouse 

源代码
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 button(&mut self, button: Button, direction: Direction) -> InputResult<()>

发送单个鼠标按键事件。例如你可以用此方法模拟左键点击。某些按键是平台特有的。

§错误

请参考 InputError 的文档以了解在哪些情况下会返回错误。

源代码

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<()>

发送鼠标滚轮事件

§Arguments
  • axis - The axis to scroll on
  • length - 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 的文档以了解在哪些情况下会返回错误。

源代码

fn main_display(&self) -> InputResult<(i32, i32)>

获取主显示屏的(宽度,高度)像素值。目前仅支持主显示屏

§错误

请参考 InputError 的文档以了解在哪些情况下会返回错误。

源代码

fn location(&self) -> InputResult<(i32, i32)>

获取鼠标位置的像素坐标

§错误

请参考 InputError 的文档以了解在哪些情况下会返回错误。

实现者§