From 898f50ecec9f0837c5bad70fee73b26ef43ab1c0 Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 16 Dec 2020 04:18:01 +0900 Subject: [PATCH] json is added --- Cargo.toml | 9 +++------ src/keyboard.rs | 5 +++-- src/lib.rs | 7 +++---- src/mouse.rs | 5 +++-- src/windows/mod.rs | 1 + src/windows/mouse.rs | 1 + 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8756d5..dc31c5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,14 +7,11 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -serde = { version = "1.0.117", optional = true } -serde_derive = { version = "1.0.117", optional = true } -serde_json = { version = "1.0", optional = true } +serde = { version = "1.0.117", features = ["derive"] } +serde_derive = { version = "1.0.117" } +serde_json = { version = "1.0" } once_cell = "1.5.2" -[features] -with_serde = ["serde", "serde_derive", "serde_json"] - [target.'cfg(target_os = "windows")'.dependencies] winapi = { version = "0.3.9", features = ["winuser", "errhandlingapi"] } diff --git a/src/keyboard.rs b/src/keyboard.rs index 4cdec30..fdbb921 100644 --- a/src/keyboard.rs +++ b/src/keyboard.rs @@ -1,5 +1,6 @@ -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] pub enum Key { Escape, Digit0, diff --git a/src/lib.rs b/src/lib.rs index 82a9139..1039577 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,13 +5,13 @@ pub use crate::windows::*; use crate::keyboard::Key; use crate::mouse::Button; +use serde::{Deserialize, Serialize}; use std::time::SystemTime; pub mod keyboard; pub mod mouse; -#[derive(Debug, Copy, Clone, PartialEq)] -#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] pub enum EventType { KeyPress(Key), KeyRelease(Key), @@ -20,8 +20,7 @@ pub enum EventType { MouseMoveTo { x: f64, y: f64 }, } -#[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct Event { pub time: SystemTime, pub event_type: EventType, diff --git a/src/mouse.rs b/src/mouse.rs index eb3ff8a..665a7c3 100644 --- a/src/mouse.rs +++ b/src/mouse.rs @@ -1,5 +1,6 @@ -#[derive(Debug, Copy, Clone, PartialEq)] -#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)] pub enum Button { Left, Middle, diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 4b9d3c3..ef2b4c9 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -8,6 +8,7 @@ use winapi::shared::minwindef::{DWORD, HINSTANCE, LPARAM, LRESULT, WPARAM}; use winapi::shared::windef::{HHOOK__, HWND}; use winapi::um::errhandlingapi::GetLastError; use winapi::um::winuser::{GetMessageW, SetWindowsHookExW, UnhookWindowsHookEx, MSG}; + pub mod keyboard; pub mod mouse; diff --git a/src/windows/mouse.rs b/src/windows/mouse.rs index bcf3d8b..9b635a5 100644 --- a/src/windows/mouse.rs +++ b/src/windows/mouse.rs @@ -226,6 +226,7 @@ impl Robot { event_type, time: SystemTime::now(), }; + HOOK_CALLBACK(event); } }