document the remaining win32 safety contracts

This commit is contained in:
2026-09-21 01:14:27 +03:00
parent 630687945a
commit 8972592b8d
6 changed files with 152 additions and 37 deletions
+4
View File
@@ -52,10 +52,14 @@ pub(crate) fn start() -> ClickRecorder {
while running_clone.load(Ordering::Relaxed) {
for (i, &(vk, button)) in buttons.iter().enumerate() {
// SAFETY: both calls are self-contained Win32 queries. `pt` is
// a local that GetCursorPos writes, and it is only read after
// the call reports success.
let state = unsafe { GetAsyncKeyState(vk) };
let pressed = (state.cast_unsigned() & 0x8000) != 0;
if pressed && !last_pressed[i] {
let mut pt = POINT::default();
// SAFETY: `pt` is a live local the call writes through.
if unsafe { GetCursorPos(&raw mut pt) }.is_ok() {
let click = Click {
time_secs: start.elapsed().as_secs_f64(),