json is added

This commit is contained in:
crusader 2020-12-16 04:18:01 +09:00
parent 26b7341b40
commit 898f50ecec
6 changed files with 14 additions and 14 deletions

View File

@ -7,14 +7,11 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = { version = "1.0.117", optional = true } serde = { version = "1.0.117", features = ["derive"] }
serde_derive = { version = "1.0.117", optional = true } serde_derive = { version = "1.0.117" }
serde_json = { version = "1.0", optional = true } serde_json = { version = "1.0" }
once_cell = "1.5.2" once_cell = "1.5.2"
[features]
with_serde = ["serde", "serde_derive", "serde_json"]
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
winapi = { version = "0.3.9", features = ["winuser", "errhandlingapi"] } winapi = { version = "0.3.9", features = ["winuser", "errhandlingapi"] }

View File

@ -1,5 +1,6 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub enum Key { pub enum Key {
Escape, Escape,
Digit0, Digit0,

View File

@ -5,13 +5,13 @@ pub use crate::windows::*;
use crate::keyboard::Key; use crate::keyboard::Key;
use crate::mouse::Button; use crate::mouse::Button;
use serde::{Deserialize, Serialize};
use std::time::SystemTime; use std::time::SystemTime;
pub mod keyboard; pub mod keyboard;
pub mod mouse; pub mod mouse;
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EventType { pub enum EventType {
KeyPress(Key), KeyPress(Key),
KeyRelease(Key), KeyRelease(Key),
@ -20,8 +20,7 @@ pub enum EventType {
MouseMoveTo { x: f64, y: f64 }, MouseMoveTo { x: f64, y: f64 },
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Event { pub struct Event {
pub time: SystemTime, pub time: SystemTime,
pub event_type: EventType, pub event_type: EventType,

View File

@ -1,5 +1,6 @@
#[derive(Debug, Copy, Clone, PartialEq)] use serde::{Deserialize, Serialize};
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
pub enum Button { pub enum Button {
Left, Left,
Middle, Middle,

View File

@ -8,6 +8,7 @@ use winapi::shared::minwindef::{DWORD, HINSTANCE, LPARAM, LRESULT, WPARAM};
use winapi::shared::windef::{HHOOK__, HWND}; use winapi::shared::windef::{HHOOK__, HWND};
use winapi::um::errhandlingapi::GetLastError; use winapi::um::errhandlingapi::GetLastError;
use winapi::um::winuser::{GetMessageW, SetWindowsHookExW, UnhookWindowsHookEx, MSG}; use winapi::um::winuser::{GetMessageW, SetWindowsHookExW, UnhookWindowsHookEx, MSG};
pub mod keyboard; pub mod keyboard;
pub mod mouse; pub mod mouse;

View File

@ -226,6 +226,7 @@ impl Robot {
event_type, event_type,
time: SystemTime::now(), time: SystemTime::now(),
}; };
HOOK_CALLBACK(event); HOOK_CALLBACK(event);
} }
} }