use crate::prelude::*;

use std::{ time };


use enigo::{
    Button, Coordinate,
    Direction::{Click, Press, Release},
    Enigo, Key, Keyboard, Mouse, Settings,
};




#[gen_特征_derive(MOD特征_sim_event)]
impl 信令路由{
    fn 模拟_鼠标点击(&self)-> impl 信令任务<String>{
        core发布信令任务!(self, 信令表::test{ 参数:"123".to_string()  },  信令表::test_回复 => 返回 )
    }
}


#[derive(Clone, Serialize, Deserialize)]//可选特征
enum 信令表{
    test{ 参数:String },
    test_回复{ 返回:String },
}
impl信令特征!(信令表, 执行函数);        //必须实现此特征


async fn 执行函数(信令路由:信令路由,id:信令ID,单个信令:信令表)->anyhow_Result<信令表>{ 
    match 单个信令{
        信令表::test{ 参数 }=>{
            anyhow_Ok信令!(信令表::test_回复 { 返回:format!("返回参数: {参数}") })
        }
        _ =>{ return Err(anyhow_err!("信令不存在")); }
    }
}








fn test(){
    let mut enigo = Enigo::new(&Settings::default()).unwrap();
    // Paste
    let _ = enigo.key(Key::Control, Press);
    let _ = enigo.key(Key::Unicode('v'), Click);
    let _ = enigo.key(Key::Control, Release);
    // Do things with the mouse
    let _ = enigo.move_mouse(500, 200, Coordinate::Abs);
    let _ = enigo.button(Button::Left, Press);
    let _ = enigo.move_mouse(100, 100, Coordinate::Rel);
    let _ = enigo.button(Button::Left, Release);
    // Enter text
    let _ = enigo.text("hello world");
}




