跳到主要内容

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 坐标。

You can specify absolute coordinates or relative from the current position.

If you use absolute coordinates, the top left corner of your monitor screen is x=0 y=0. Move the cursor down the screen by increasing the y and to the right by increasing x coordinate.

If you use relative coordinates, a positive x value moves the mouse cursor x pixels to the right. A negative value for x moves the mouse cursor to the left. A positive value of y moves the mouse cursor down, a negative one moves the mouse cursor up.

§错误

请参考 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.

With Axis::Vertical, a positive length will result in scrolling down and negative ones up. With Axis::Horizontal, a positive length will result in scrolling to the right and negative ones to the left

§错误

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

源代码

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

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

§错误

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

源代码

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

获取鼠标位置的像素坐标

§错误

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

实现者§