How to get the current screen position of the mouse in tauri? #4943
-
I have an application that wants to get the window position where the mouse is, but I can't find the corresponding api, please help me thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
FabianLars
Aug 15, 2022
Replies: 2 comments 1 reply
-
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
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
wkl007
-
it works. add to Cargo.tom
add main.rs
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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