-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(!): migrate mousepos to mousepos-rs
- Loading branch information
Showing
7 changed files
with
63 additions
and
66 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ resolver = "2" | |
members = [ | ||
"carnival-web", | ||
"carnival-matchserver", | ||
"carnival-matchserver/tooling/mousepos" | ||
] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "mousepos" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
windows = { version = "0.51.1", features = [ | ||
"Win32_Foundation", | ||
"Win32_UI_Input_KeyboardAndMouse", | ||
"Win32_UI_WindowsAndMessaging", | ||
] } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::thread::sleep; | ||
use std::time::Duration; | ||
use windows::core::Result; | ||
use windows::Win32::Foundation::POINT; | ||
use windows::Win32::UI::Input::KeyboardAndMouse::GetAsyncKeyState; | ||
use windows::Win32::UI::WindowsAndMessaging::GetCursorPos; | ||
|
||
const DELAY: Duration = Duration::from_millis(25); | ||
const TRIGGER_KEY: i32 = 'K' as i32; | ||
|
||
#[derive(Default)] | ||
struct CursorState { | ||
x: i32, | ||
y: i32, | ||
} | ||
|
||
impl CursorState { | ||
/// Update cursor coordinates. | ||
fn update(&mut self, new_pos: POINT) { | ||
self.x = new_pos.x; | ||
self.y = new_pos.y; | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let mut cursor_pos = POINT { x: 0, y: 0 }; | ||
let mut state = CursorState::default(); | ||
|
||
loop { | ||
// Check if the trigger key is pressed and try to get the cursor position. | ||
if unsafe { GetAsyncKeyState(TRIGGER_KEY) & 1 } != 0 | ||
&& unsafe { GetCursorPos(&mut cursor_pos).is_ok() } | ||
{ | ||
// Log the cursor state before updating it. | ||
println!("{{ x = {}, y = {}, delay = {}}},", state.x, state.y, DELAY.as_millis()); | ||
state.update(cursor_pos); | ||
} | ||
|
||
// Sleep for a defined delay to limit CPU usage. | ||
sleep(DELAY); | ||
} | ||
} |