Compare commits

...

4 Commits

6 changed files with 45 additions and 10 deletions

4
.gitignore vendored
View File

@ -1 +1,5 @@
/target /target
# Ignore environment directories
/.idea
/.vscode

7
Cargo.lock generated
View File

@ -13,6 +13,7 @@ name = "skyhook"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"cancellation", "cancellation",
"winsafe",
] ]
[[package]] [[package]]
@ -21,3 +22,9 @@ version = "0.1.0"
dependencies = [ dependencies = [
"skyhook", "skyhook",
] ]
[[package]]
name = "winsafe"
version = "0.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd38859e955532136a544e7e6a6a1239a3f4fe48ecf67c63500ec9f527f8381"

View File

@ -1,3 +1,3 @@
# native # Skyhook-Native
Very simple Keyboard & Mouse hook, meant for rhythm games. Very simple Keyboard & Mouse hook, meant for rhythm games.

View File

@ -11,3 +11,4 @@ edition = "2021"
[dependencies] [dependencies]
cancellation = "0.1.0" cancellation = "0.1.0"
winsafe = "0.0.5"

View File

@ -1,10 +1,10 @@
// unsafe stuff
extern crate user32;
extern crate winapi;
// safe stuff // safe stuff
use winsafe::co::WH;
extern crate winsafe; extern crate winsafe;
/*
//#region Constants //#region Constants
const KEY_PRESSED: i32 = 0x8000; const KEY_PRESSED: i32 = 0x8000;
const WM_KEYDOWN: i32 = 0x0100; const WM_KEYDOWN: i32 = 0x0100;
@ -14,11 +14,26 @@ const WM_SYSKEYUP: i32 = 0x0105;
const WH_KEYBOARD_LL: i32 = 13; const WH_KEYBOARD_LL: i32 = 13;
const WH_MOUSE_LL: i32 = 14; const WH_MOUSE_LL: i32 = 14;
//#endregion //#endregion
*/
//#region Commons //#region Commons
static mut hook_id: winsafe::HHOOK = 0; static mut hook_id: Option<winsafe::HHOOK> = None;
pub fn start() -> () { pub fn start() -> () {
/*
unsafe {
hook_id = Some(winsafe::HHOOK::SetWindowsHookEx(
WH::KEYBOARD_LL,
hook_callback,
winsafe::HINSTANCE::NULL,
Some(0)));
match hook_id {
Some(x) => (),
None => panic!(),
}
}*/
/*
unsafe { unsafe {
let hook_id = let hook_id =
user32::SetWindowsHookExA(WH_KEYBOARD_LL, Some(hook_callback), std::ptr::null_mut(), 0); user32::SetWindowsHookExA(WH_KEYBOARD_LL, Some(hook_callback), std::ptr::null_mut(), 0);
@ -27,14 +42,14 @@ pub fn start() -> () {
// Release hook // Release hook
user32::UnhookWindowsHookEx(hook_id); user32::UnhookWindowsHookEx(hook_id);
} }*/
} }
pub fn stop() -> () {} pub fn stop() -> () {}
//#endregion //#endregion
extern "system" fn hook_callback(code: i32, wParam: u64, lParam: i64) -> i64 { extern "system" fn hook_callback(code: i32, wParam: usize, lParam: isize) -> isize {
unsafe { /*unsafe {
assert!( assert!(
hook_id != 0, hook_id != 0,
format!( format!(
@ -42,7 +57,7 @@ extern "system" fn hook_callback(code: i32, wParam: u64, lParam: i64) -> i64 {
winapi::um::errhandlingapi::GetLastError() winapi::um::errhandlingapi::GetLastError()
) )
); // GetLastError is an unsafe method ); // GetLastError is an unsafe method
} }*/
return 0; return 0;
} }

View File

@ -1 +1,9 @@
mod hook; mod hook;
pub fn start() {
hook::start()
}
pub fn stop() {
hook::stop()
}