Created
September 3, 2023 15:51
-
-
Save EwanFox/6cf25e945068cf7c10c7d736b4d7520d to your computer and use it in GitHub Desktop.
cursed ass cele thing only on windows becuase yeah
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
use std::time::Duration; | |
use winapi::shared::windef::POINT; | |
use winapi::um::winuser::INPUT; | |
fn main() { | |
println!("Hello, world!"); | |
unsafe { | |
loop { | |
let heights: (i32, i32) = get_screen_size(); | |
let pos: (i32,i32) = get_mouse_pos(); | |
let chunk = calculate_chunk(heights.0, heights.1, pos.0, pos.1); | |
println!("{}, {}",pos.0,pos.1); | |
match chunk { | |
0=> { | |
press_key(0x25,0); | |
press_key(0x26, 0); | |
println!("top-left") | |
} | |
2=> { | |
press_key(0x25,0); | |
press_key(0x28, 0); | |
println!("bottom-left") | |
} | |
6=> { | |
press_key(0x27,0); | |
press_key(0x26, 0); | |
println!("top-right") | |
} | |
8=> { | |
press_key(0x28,0); | |
press_key(0x27, 0); | |
println!("bottom-right") | |
} | |
1 =>{ | |
press_key(0x25,0); | |
println!("left") | |
}, | |
3 => { | |
press_key(0x26,0); | |
println!("up") | |
}, | |
5 => { | |
press_key(0x28,0); | |
println!("down") | |
}, | |
7=> { | |
press_key(0x27,0); | |
println!("right") | |
} | |
_ => { | |
} | |
}; | |
std::thread::sleep(Duration::from_micros(5)); | |
} | |
} | |
} | |
fn get_mouse_pos() -> (i32, i32) { | |
let mut point = POINT {x:0,y:0}; | |
unsafe { | |
::winapi::um::winuser::GetCursorPos(&mut point as *mut POINT); | |
}; | |
(point.x, point.y) | |
} | |
fn get_screen_size() -> (i32,i32) { | |
unsafe { | |
(::winapi::um::winuser::GetSystemMetrics(1),::winapi::um::winuser::GetSystemMetrics(0)) | |
} | |
} | |
unsafe fn press_key(vk: u16, flags:u32) { | |
let mut input = winapi::um::winuser::INPUT { | |
type_: winapi::um::winuser::INPUT_KEYBOARD, | |
u: std::mem::zeroed() | |
}; | |
*input.u.ki_mut() = winapi::um::winuser::KEYBDINPUT { | |
wVk: vk, | |
wScan: 0, | |
dwFlags: flags, | |
time: 0, | |
dwExtraInfo: 0, | |
}; | |
::winapi::um::winuser::SendInput(1, &mut input, std::mem::size_of::<winapi::um::winuser::INPUT>() as i32); | |
} | |
fn calculate_chunk(h: i32, w:i32, x: i32, y: i32) -> u8 { | |
let chunkx = i32::div_euclid(x,i32::div_euclid(w,3)); | |
let chunky = i32::div_euclid(y,i32::div_euclid(h,3)); | |
match (chunkx, chunky) { | |
(0,0) => { | |
0 | |
}, | |
(0,1) => { | |
1 | |
}, | |
(0,2) => { | |
2 | |
}, | |
(1,0) => { | |
3 | |
}, | |
(1,1) => { | |
4 | |
}, | |
(1,2) => { | |
5 | |
}, | |
(2,0) => { | |
6 | |
}, | |
(2,1) => { | |
7 | |
}, | |
(2,2) => { | |
8 | |
}, | |
_ => { | |
9 | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment