Skip to content

How to get the current screen position of the mouse in tauri? #4943

Answered by FabianLars
wkl007 asked this question in Q&A
Discussion options

You must be logged in to vote

We don't have an API for this yet. But as a starting point, at least for Windows someone posted rust code on discord yesterday: https://discord.com/channels/616186924390023171/1008442125337235506/1008451225123037264

#[derive(Serialize)]
pub struct MousePos {
  pub x: i32,
  pub y: i32,
}

pub fn mouse_pos() -> MousePos {
  let mut win_cursor_pos =  POINT {
      x: 0,
      y: 0,
  };
  unsafe {
    GetCursorPos(&mut win_cursor_pos);
  }
  println!("pos is {:?}",win_cursor_pos);
  let mouse_pos= MousePos { x: win_cursor_pos.x, y: win_cursor_pos.y };
  return mouse_pos
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@wkl007
Comment options

Answer selected by wkl007
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants