Skip to content

Commit

Permalink
Inverse mouse and scroll Y direction
Browse files Browse the repository at this point in the history
  • Loading branch information
positiveway committed May 16, 2024
1 parent 88fc263 commit c3da377
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mouse-keyboard-input"
version = "0.6.1"
version = "0.7.1"
authors = ["Andrew Korovkin <[email protected]>"]
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sudo apt install libudev-dev libevdev-dev libhidapi-dev

Add to `Cargo.toml`
```
mouse-keyboard-input = "0.6.1"
mouse-keyboard-input = "0.7.1"
```
To use the latest development version:
```
Expand Down Expand Up @@ -95,8 +95,8 @@ fn main() {
for _ in 1..5 {
thread::sleep(Duration::from_secs(1));
// scroll vertically by 100
device.scroll_vertical(100).unwrap();
// scroll down by 100
device.scroll_vertical(-100).unwrap();
// move cursor vertically the from current position by 50
device.move_mouse(50, 50).unwrap();
//click the left mouse button
Expand Down
4 changes: 2 additions & 2 deletions examples/mouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ fn main() {
for _ in 1..5 {
thread::sleep(Duration::from_secs(1));

// scroll vertically by 100
device.scroll_y(100).unwrap();
// scroll down by 100
device.scroll_y(-100).unwrap();
// move cursor vertically from the current position by 50
device.move_mouse(50, 50).unwrap();
//click the left mouse button
Expand Down
14 changes: 7 additions & 7 deletions src/virtual_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,26 +197,26 @@ impl VirtualDevice {

#[inline]
pub fn send_mouse_move_y(y: Coord, sender: &ChannelSender) -> EmptyResult {
sender.send((EV_REL, REL_Y, y))?;
sender.send((EV_REL, REL_Y, -y))?;
Ok(())
}

#[inline]
pub fn send_mouse_move(x: Coord, y: Coord, sender: &ChannelSender) -> EmptyResult {
sender.send((EV_REL, REL_X, x))?;
sender.send((EV_REL, REL_Y, y))?;
sender.send((EV_REL, REL_Y, -y))?;
Ok(())
}

#[inline]
pub fn send_scroll_x(value: Coord, sender: &ChannelSender) -> EmptyResult {
sender.send((EV_REL, REL_HWHEEL, -value))?;
sender.send((EV_REL, REL_HWHEEL, value))?;
Ok(())
}

#[inline]
pub fn send_scroll_y(value: Coord, sender: &ChannelSender) -> EmptyResult {
sender.send((EV_REL, REL_WHEEL, -value))?;
sender.send((EV_REL, REL_WHEEL, value))?;
Ok(())
}

Expand Down Expand Up @@ -274,14 +274,14 @@ impl VirtualDevice {

#[inline]
pub fn move_mouse_y(&mut self, y: Coord) -> EmptyResult {
self.write(EV_REL, REL_Y, y)?;
self.write(EV_REL, REL_Y, -y)?;
self.synchronize()
}

#[inline]
pub fn move_mouse(&mut self, x: Coord, y: Coord) -> EmptyResult {
self.write(EV_REL, REL_X, x)?;
self.write(EV_REL, REL_Y, y)?;
self.write(EV_REL, REL_Y, -y)?;
self.synchronize()
}

Expand All @@ -293,7 +293,7 @@ impl VirtualDevice {

#[inline]
pub fn scroll_y(&mut self, value: Coord) -> EmptyResult {
self.write(EV_REL, REL_WHEEL, -value)?;
self.write(EV_REL, REL_WHEEL, value)?;
self.synchronize()
}

Expand Down

0 comments on commit c3da377

Please sign in to comment.