From 769b2cb8c25a8a4e4aeb5dc5aceec0584d95a370 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Sun, 30 Oct 2022 15:33:24 +0100 Subject: [PATCH 01/12] started work on the conversion table Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/hid_table.rs | 1 + src-tauri/src/main.rs | 8 +- src-tauri/src/wooting_macros_library.rs | 266 +----------------------- 3 files changed, 18 insertions(+), 257 deletions(-) diff --git a/src-tauri/src/hid_table.rs b/src-tauri/src/hid_table.rs index e69de29b..8b137891 100644 --- a/src-tauri/src/hid_table.rs +++ b/src-tauri/src/hid_table.rs @@ -0,0 +1 @@ + diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 24bd4817..753e34a2 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -17,8 +17,8 @@ use crate::wooting_macros_library::*; //use crate::wooting_macros_library; -mod wooting_macros_library; mod hid_table; +mod wooting_macros_library; #[derive(Debug, Deserialize)] #[serde(rename_all = "PascalCase")] @@ -30,7 +30,11 @@ pub struct ApplicationConfig { fn main() { tauri::Builder::default() // This is where you pass in your commands - .invoke_handler(tauri::generate_handler![export_frontend, import_frontend, push_frontend_first]) + .invoke_handler(tauri::generate_handler![ + export_frontend, + import_frontend, + push_frontend_first + ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index e0ee641e..ca83de5a 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -11,8 +11,6 @@ use serde::Serialize; use crate::ApplicationConfig; -/// MacroType that wraps the Macro struct. Depending on the type we decide what to do. -/// This does not yet do anything. #[derive(Debug)] pub enum MacroType { Single { data: Macro }, @@ -21,10 +19,6 @@ pub enum MacroType { MultiLevel { data: Macro }, } -/// Key contains an rdev::Key enum to be pressed. -/// * `keypress` - an rdev::Key enum of the key that will be pressed -/// * `press_wait_delay_after` - time::Duration argument that makes the macro wait after (this is subject to change potentially) -/// * `press_duration` - time::Duration for how long the key should stay pressed for (currently not implemented or used) #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] struct KeyPress { keypress: u32, @@ -32,20 +26,11 @@ struct KeyPress { } impl KeyPress { - /// Executes an action on key up. - /// TODO: Meant to search the event list and remove all duplicates of the keys being pressed. - /// This should be either paired with each keypress, or called after registering that key release to clean up the array fn execute_key_up(&self, key_to_release: &rdev::Key) { send(&EventType::KeyRelease(*key_to_release)); } - /// Executes the actual keypress according to what it should be - fn execute_key_down(&self) { - //send(&EventType::KeyPress(self.keypress)); - //thread::sleep(self.press_duration); - - //self.execute_key_up(&self.keypress); - } + fn execute_key_down(&self) {} } ///Delay for the sequence @@ -53,15 +38,6 @@ type Delay = u32; //TODO: Make a hashmap that links to trigger:¯o -/// Action event type is the *output* action that is sent to the system after being processed by the backend. -/// Each of these have a struct embedded within them to provide the necessary data for the execution. -/// Think of this as plugins. Currently supported: -/// * `KeyPressEvent` - A simple keypress (which releases after a while). -/// * `SystemEvent` - An action like launching a browser, copying a file, pasting from the clipboard, etc. -/// * `PhillipsHueCommand` - After initializing, you can use this to control lights via the BridgeV2. -/// * `OBS` - OpenBroadcastSoftware integration -/// * `DiscordCommand` - Discord integration (muting microphone, deafening) -/// * `UnicodeDirect` - Output a Unicode symbol of choice #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum ActionEventType { //TODO: rewrite the tuples into structs @@ -75,60 +51,20 @@ pub enum ActionEventType { //TODO: Move the delay after here as an action } -// impl std::fmt::Display for ActionEventType { -// fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { -// let mut buffer_text: String = "".to_string(); -// let mut number = 0; -// -// match &self { -// ActionEventType::KeyPressEvent { data: i } => { -// buffer_text += format!( -// "\n\t\tKey #{}\n\t\tKey: {:?}\tDelayAfterPress: {} ms\tDuration: {} ms", -// number, -// i.keypress, -// i.press_wait_delay_after.as_millis(), -// i.press_duration.as_millis() -// ) -// .as_str(); -// number += 1; -// } -// ActionEventType::SystemEvent { action: _ } => {} -// ActionEventType::PhillipsHueCommand() => {} -// ActionEventType::OBS() => {} -// ActionEventType::DiscordCommand {} => {} -// ActionEventType::UnicodeDirect {} => {} -// } -// -// write!(f, "{}", buffer_text) -// } -// } - -/// These are the events that can come from within the OS and are supported as triggers for running a macro. -/// Currently supported: -/// * `KeyPressEvent` - Very much like the output counterpart, a key event that can be caught using a grab feature and processed. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum TriggerEventType { KeyPressEvent { data: KeyPress }, } -/// The list of events that are currently happening (basically a list of all keys or buttons currently being pressed). -/// Helps to check this list after a change to see if to trigger a macro. #[derive(Debug, Clone)] struct EventList(Vec); -/// Action is a structure currently unused. -/// Action serves for the system actions (paste clipboard, etc). Not used yet. #[derive(Debug, Clone)] pub struct Action { pub action: char, pub press_wait_delay_after: time::Duration, } -/// Macro is the main building block that has several fields. -/// * `name` - Name of the macro. -/// * `body` - Actions to execute within a macro. -/// * `trigger` - The trigger event that can trigger the macro to execute -/// * `active` - whether the macro is active (should be executed when conditions meet) or not. #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Macro { name: String, @@ -137,27 +73,6 @@ pub struct Macro { active: bool, } -// impl std::fmt::Display for Macro { -// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { -// let mut buffer_text: String = "".to_string(); -// let mut number = 0; -// -// buffer_text += format!( -// "There are {} keys in the macro {}.\n", -// self.body.len(), -// self.name -// ) -// .as_str(); -// -// for i in &self.body { -// buffer_text += format!("Key {}: {}", number, i).as_str(); -// number += 1; -// } -// -// write!(f, "{}", buffer_text) -// } -// } - #[tauri::command] pub fn export_frontend(data: MacroData) -> String { let data_return = data.export_data(); @@ -173,6 +88,14 @@ pub fn push_frontend_first() -> Result { Ok(res.to_string()) } +fn push_backend_first() -> MacroData { + let path = "./data_json.json"; + let data = fs::read_to_string(path).expect("Unable to read file"); + + let deserialized: MacroData = serde_json::from_str(&data).unwrap(); + deserialized +} + #[tauri::command] pub fn import_frontend(mut data: MacroData, input: MacroData) { data.import_data(input); @@ -203,35 +126,6 @@ impl MacroData { } } -// -// impl std::fmt::Display for MacroData { -// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { -// let mut buffer_text: String = "".to_string(); -// let mut number = 0; -// -// buffer_text += format!("There are {} macro groups.\n", &self.0.len()).as_str(); -// -// for i in &self.0 { -// buffer_text += format!( -// "\tGroup {}\n\tGroupName: {}\n\tActive: {}\n+++++++++++\n", -// number, i.name, i.active -// ) -// .as_str(); -// number += 1; -// buffer_text += format!("\nMacro {}\n{}", i.name, i).as_str(); -// } -// -// write!(f, "{}", buffer_text) -// } -// } - -///Trait implementation for MacroData - -///MacroGroup is a group of macros. It can be active or inactive. Contains an icon and a name. -/// * `name` - String based name of the MacroGroup -/// * `icon` - Placeholder for now -/// * `macros` - Macros (vector) that belong to a group -/// * `active` - Whether they should be executable #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Collection { name: String, @@ -240,147 +134,12 @@ pub struct Collection { macros: Vec, active: bool, } -// -// impl std::fmt::Display for MacroGroup { -// fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { -// let mut buffer_text: String = "".to_string(); -// let mut number = 0; -// -// buffer_text += format!( -// "There are {} macros in the group {}.\n", -// &self.macros.len(), -// &self.name -// ) -// .as_str(); -// -// for i in &self.macros { -// buffer_text += format!( -// "========\n\tMacro # {}\n\tMacroName: {}\tActive: {}", -// number, i.name, i.active -// ) -// .as_str(); -// for j in &i.body { -// buffer_text += format!("\n\t\tKeys: {}\n", j).as_str(); -// } -// number += 1; -// } -// -// write!(f, "{}", buffer_text) -// } -// } ///Main loop for now (of the library) /// * `config` - &ApplicationConfig from the parsed JSON config file of the app. pub fn run_this(config: &ApplicationConfig) { - println!("Character {}: {}", 'c', 'c' as u32); - - // push_frontend_first(); - - // let testing_action = ActionEventType::SystemEvent { - // action: Action { - // action: 'd', - // press_wait_delay_after: time::Duration::from_millis(5), - // } - // }; - - //Very temporary debugging only variable (so I can precisely see and manipulate data - let mut testing_macro_full: MacroData = MacroData { - 0: vec![ - Collection { - name: "Main group".to_string(), - icon: 'i'.to_string(), - macros: vec![Macro { - name: "Paste".to_string(), - sequence: vec![ - ActionEventType::KeyPressEvent { - data: KeyPress { - keypress: 12, - - press_duration: 50, - }, - }, - ActionEventType::KeyPressEvent { - data: KeyPress { - keypress: 13, - - press_duration: 50, - }, - }, - ], - trigger: TriggerEventType::KeyPressEvent { - data: KeyPress { - keypress: 14, - - press_duration: 50, - }, - }, - active: true, - }], - active: true, - }, - Collection { - name: "Fun macro group".to_string(), - icon: 'i'.to_string(), - macros: vec![ - Macro { - name: "Havo".to_string(), - sequence: vec![ - ActionEventType::KeyPressEvent { - data: KeyPress { - keypress: 14, - - press_duration: 50, - }, - }, - ActionEventType::KeyPressEvent { - data: KeyPress { - keypress: 13, - - press_duration: 50, - }, - }, - ActionEventType::KeyPressEvent { - data: KeyPress { - keypress: 12, - - press_duration: 50, - }, - }, - ], - trigger: TriggerEventType::KeyPressEvent { - data: KeyPress { - keypress: 22, - - press_duration: 50, - }, - }, - active: true, - }, - Macro { - name: "Svorka".to_string(), - sequence: vec![ActionEventType::KeyPressEvent { - data: KeyPress { - keypress: 23, - - press_duration: 50, - }, - }], - trigger: TriggerEventType::KeyPressEvent { - data: KeyPress { - keypress: 24, - - press_duration: 50, - }, - }, - active: true, - }, - ], - active: true, - }, - ], - }; - - //testing_macro_full.export_data(); + // Get data from the config file. + let mut testing_macro_full: MacroData = push_backend_first(); //TODO: make this a grab instead of listen let (schan, rchan) = channel(); @@ -426,8 +185,6 @@ pub fn run_this(config: &ApplicationConfig) { //TODO: Make a translation table to a hashmap from a keycode HID compatible -> library rdev enums. } -//Temporary "option" for either using the input grab or not. - fn send(event_type: &EventType) { let delay = time::Duration::from_millis(20); match simulate(event_type) { @@ -440,7 +197,6 @@ fn send(event_type: &EventType) { thread::sleep(delay); } -///Gets user's text. fn get_user_input(display_text: String) -> String { println!("{}\n", display_text); From bebf3fec314844fa614682ebceaa34295177bc3d Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Sun, 30 Oct 2022 16:16:31 +0100 Subject: [PATCH 02/12] Upgraded the backend format - now a trigger is a vector of keypresses Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/data_json.json | 30 +++--- src-tauri/src/main.rs | 18 ++-- src-tauri/src/wooting_macros_library.rs | 130 +++++++++++++++++++++++- 3 files changed, 155 insertions(+), 23 deletions(-) diff --git a/src-tauri/data_json.json b/src-tauri/data_json.json index fbcf19ae..98a2681e 100644 --- a/src-tauri/data_json.json +++ b/src-tauri/data_json.json @@ -25,10 +25,12 @@ ], "trigger": { "KeyPressEvent": { - "data": { - "keypress": 14, - "press_duration": 50 - } + "data": [ + { + "keypress": 14, + "press_duration": 50 + } + ] } }, "active": true @@ -70,10 +72,12 @@ ], "trigger": { "KeyPressEvent": { - "data": { - "keypress": 22, - "press_duration": 50 - } + "data": [ + { + "keypress": 22, + "press_duration": 50 + } + ] } }, "active": true @@ -92,10 +96,12 @@ ], "trigger": { "KeyPressEvent": { - "data": { - "keypress": 24, - "press_duration": 50 - } + "data": [ + { + "keypress": 24, + "press_duration": 50 + } + ] } }, "active": true diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 753e34a2..6bd82c8c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -28,15 +28,15 @@ pub struct ApplicationConfig { } fn main() { - tauri::Builder::default() - // This is where you pass in your commands - .invoke_handler(tauri::generate_handler![ - export_frontend, - import_frontend, - push_frontend_first - ]) - .run(tauri::generate_context!()) - .expect("error while running tauri application"); + // tauri::Builder::default() + // // This is where you pass in your commands + // .invoke_handler(tauri::generate_handler![ + // export_frontend, + // import_frontend, + // push_frontend_first + // ]) + // .run(tauri::generate_context!()) + // .expect("error while running tauri application"); let mut config: ApplicationConfig = ApplicationConfig { use_input_grab: false, diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index ca83de5a..dd03c2b3 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -2,6 +2,7 @@ use std::{fs, result, thread, time}; use std::collections::HashMap; use std::fmt::{format, Formatter}; use std::fs::File; +use std::hash::Hash; use std::str::{Bytes, FromStr}; use std::sync::mpsc::channel; use std::time::Duration; @@ -53,7 +54,9 @@ pub enum ActionEventType { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum TriggerEventType { - KeyPressEvent { data: KeyPress }, + KeyPressEvent { + data: Vec, + }, } #[derive(Debug, Clone)] @@ -124,8 +127,28 @@ impl MacroData { *self = input; self.export_data(); } + + // /// Extracts the data + // fn extract_triggers(&self){ + // let mut triggers: TriggerDataHash; + // + // //convert to enum of rdev + // + // + // for search in self.0{ + // for trig in search.macros { + // match trig.trigger { + // TriggerEventType::KeyPressEvent {data} => { + // // + // } + // } + // } + // } + // } } +// type TriggerDataHash = HashMap<>; + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Collection { name: String, @@ -138,9 +161,111 @@ pub struct Collection { ///Main loop for now (of the library) /// * `config` - &ApplicationConfig from the parsed JSON config file of the app. pub fn run_this(config: &ApplicationConfig) { + // let mut testing_macro_full: MacroData = MacroData { + // 0: vec![ + // Collection { + // name: "Main group".to_string(), + // icon: 'i'.to_string(), + // macros: vec![Macro { + // name: "Paste".to_string(), + // sequence: vec![ + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 12, + // + // press_duration: 50, + // }, + // }, + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 13, + // + // press_duration: 50, + // }, + // }, + // ], + // trigger: TriggerEventType::KeyPressEvent { + // data: vec![KeyPress { + // keypress: 14, + // + // press_duration: 50, + // }], + // }, + // active: true, + // }], + // active: true, + // }, + // Collection { + // name: "Fun macro group".to_string(), + // icon: 'i'.to_string(), + // macros: vec![ + // Macro { + // name: "Havo".to_string(), + // sequence: vec![ + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 14, + // + // press_duration: 50, + // }, + // }, + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 13, + // + // press_duration: 50, + // }, + // }, + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 12, + // + // press_duration: 50, + // }, + // }, + // ], + // trigger: TriggerEventType::KeyPressEvent { + // data: vec![KeyPress { + // keypress: 22, + // + // press_duration: 50, + // }], + // }, + // active: true, + // }, + // Macro { + // name: "Svorka".to_string(), + // sequence: vec![ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 23, + // + // press_duration: 50, + // }, + // }], + // trigger: TriggerEventType::KeyPressEvent { + // data: vec![KeyPress { + // keypress: 24, + // + // press_duration: 50, + // }], + // }, + // active: true, + // }, + // ], + // active: true, + // }, + // ], + // }; + + //testing_macro_full.export_data(); + // Get data from the config file. let mut testing_macro_full: MacroData = push_backend_first(); + // Serve to the frontend. + push_frontend_first(); + + //TODO: make this a grab instead of listen let (schan, rchan) = channel(); let _listener = thread::spawn(move || { @@ -176,7 +301,7 @@ pub fn run_this(config: &ApplicationConfig) { } EventType::MouseMove { x, y } => (), EventType::Wheel { delta_x, delta_y } => { - println!("{}, {}", delta_x, delta_y) + } } } @@ -185,6 +310,7 @@ pub fn run_this(config: &ApplicationConfig) { //TODO: Make a translation table to a hashmap from a keycode HID compatible -> library rdev enums. } + fn send(event_type: &EventType) { let delay = time::Duration::from_millis(20); match simulate(event_type) { From 61c496dedf7448463a312fd988dd2d3e9cbb38cf Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Sun, 30 Oct 2022 17:20:37 +0100 Subject: [PATCH 03/12] started working on the key conversion HID code hashmap Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/Cargo.lock | 23 +-- src-tauri/Cargo.toml | 1 + src-tauri/src/hid_table.rs | 182 ++++++++++++++++++++++++ src-tauri/src/wooting_macros_library.rs | 34 +++-- 4 files changed, 211 insertions(+), 29 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 143a6a09..9ce4bbcc 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -295,9 +295,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.73" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" +checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574" [[package]] name = "cesu8" @@ -2001,9 +2001,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "open" @@ -4192,13 +4192,14 @@ dependencies = [ name = "wooting-macros" version = "0.1.0" dependencies = [ - "halfbrown", - "idasen-cli", - "rdev", - "serde", - "serde_json", - "tauri", - "tauri-build", + "halfbrown", + "idasen-cli", + "lazy_static", + "rdev", + "serde", + "serde_json", + "tauri", + "tauri-build", ] [[package]] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index eea3ece1..c5a3146a 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -19,6 +19,7 @@ tauri = { version = "1.1", features = ["api-all"] } rdev = { version = "0.5.1", features = ["unstable_grab", "serde", "serialize"] } halfbrown = { version = "0.1.15", features = ["serde"] } idasen-cli = "0.1.0" +lazy_static = "1.4.0" [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/hid_table.rs b/src-tauri/src/hid_table.rs index 8b137891..3398e99d 100644 --- a/src-tauri/src/hid_table.rs +++ b/src-tauri/src/hid_table.rs @@ -1 +1,183 @@ +use std::collections::HashMap; +use std::hash::Hash; +use lazy_static::lazy_static; +use rdev::Key; + +lazy_static! { +static ref SCANCODE_MAP: HashMap = { + let mut scancode: HashMap = HashMap::new(); + scancode.insert(0x04, rdev::Key::KeyA); //US_A + scancode.insert(0x05, rdev::Key::KeyB); //US_B + scancode.insert(0x06, rdev::Key::KeyC); //US_C + scancode.insert(0x07, rdev::Key::KeyD); //US_D + + scancode.insert(0x08, rdev::Key::KeyE); //US_E + scancode.insert(0x09, rdev::Key::KeyF); //US_F + scancode.insert(0x0a, rdev::Key::KeyG); //US_G + scancode.insert(0x0b, rdev::Key::KeyH); //US_H + scancode.insert(0x0c, rdev::Key::KeyI); //US_I + scancode.insert(0x0d, rdev::Key::KeyJ); //US_J + scancode.insert(0x0e, rdev::Key::KeyK); //US_K + scancode.insert(0x0f, rdev::Key::KeyL); //US_L + + scancode.insert(0x10, rdev::Key::KeyM); //US_M + scancode.insert(0x11, rdev::Key::KeyN); //US_N + scancode.insert(0x12, rdev::Key::KeyO); //US_O + scancode.insert(0x13, rdev::Key::KeyP); //US_P + scancode.insert(0x14, rdev::Key::KeyQ); //US_Q + scancode.insert(0x15, rdev::Key::KeyR); //US_R + scancode.insert(0x16, rdev::Key::KeyS); //US_S + scancode.insert(0x17, rdev::Key::KeyT); //US_T + + scancode.insert(0x18, rdev::Key::KeyU); //US_U + scancode.insert(0x19, rdev::Key::KeyV); //US_V + scancode.insert(0x1a, rdev::Key::KeyW); //US_W + scancode.insert(0x1b, rdev::Key::KeyX); //US_X + scancode.insert(0x1c, rdev::Key::KeyY); //US_Y + scancode.insert(0x1d, rdev::Key::KeyZ); //US_Z + scancode.insert(0x1e, rdev::Key::Num1); //DIGIT1 + scancode.insert(0x1f, rdev::Key::Num2); //DIGIT2 + + scancode.insert(0x20, rdev::Key::Num3); //DIGIT3 + scancode.insert(0x21, rdev::Key::Num4); //DIGIT4 + scancode.insert(0x22, rdev::Key::Num5); //DIGIT5 + scancode.insert(0x23, rdev::Key::Num6); //DIGIT6 + scancode.insert(0x24, rdev::Key::Num7); //DIGIT7 + scancode.insert(0x25, rdev::Key::Num8); //DIGIT8 + scancode.insert(0x26, rdev::Key::Num9); //DIGIT9 + scancode.insert(0x27, rdev::Key::Num0); //DIGIT0 + + scancode.insert(0x28, rdev::Key::Return); //ENTER + scancode.insert(0x29, rdev::Key::Escape); //ESCAPE + scancode.insert(0x2a, rdev::Key::Backspace); //BACKSPACE + scancode.insert(0x2b, rdev::Key::Tab); //TAB + scancode.insert(0x2c, rdev::Key::Space); //SPACE + scancode.insert(0x2d, rdev::Key::Minus); //MINUS + scancode.insert(0x2e, rdev::Key::Equal); //EQUAL + scancode.insert(0x2f, rdev::Key::LeftBracket); //BRACKET_LEFT + + scancode.insert(0x30, rdev::Key::RightBracket); //BRACKET_RIGHT + scancode.insert(0x31, rdev::Key::BackSlash); //BACKSLASH + + //scancode.insert(0x32, 0x0000); //INTL_HASH + + scancode.insert(0x33, rdev::Key::SemiColon); //SEMICOLON + scancode.insert(0x34, rdev::Key::Quote); //QUOTE + scancode.insert(0x35, rdev::Key::BackQuote); //BACKQUOTE + scancode.insert(0x36, rdev::Key::Comma); //COMMA + scancode.insert(0x37, rdev::Key::Dot); //PERIOD + + scancode.insert(0x38, rdev::Key::Slash); //SLASH + scancode.insert(0x39, rdev::Key::CapsLock); //CAPS_LOCK + scancode.insert(0x3a, rdev::Key::F1); //F1 + scancode.insert(0x3b, rdev::Key::F2); //F2 + scancode.insert(0x3c, rdev::Key::F3); //F3 + scancode.insert(0x3d, rdev::Key::F4); //F4 + scancode.insert(0x3e, rdev::Key::F5); //F5 + scancode.insert(0x3f, rdev::Key::F6); //F6 + + scancode.insert(0x40, rdev::Key::F7); //F7 + scancode.insert(0x41, rdev::Key::F8); //F8 + scancode.insert(0x42, rdev::Key::F9); //F9 + scancode.insert(0x43, rdev::Key::F10); //F10 + scancode.insert(0x44, rdev::Key::F11); //F11 + scancode.insert(0x45, rdev::Key::F12); //F12 + scancode.insert(0x46, rdev::Key::PrintScreen); //PRINT_SCREEN + scancode.insert(0x47, rdev::Key::ScrollLock); //SCROLL_LOCK + + scancode.insert(0x48, rdev::Key::Pause); //PAUSE + scancode.insert(0x49, rdev::Key::Insert); //INSERT + scancode.insert(0x4a, rdev::Key::Home); //HOME + scancode.insert(0x4b, rdev::Key::PageUp); //PAGE_UP + scancode.insert(0x4c, rdev::Key::Delete); //DEL + scancode.insert(0x4d, rdev::Key::End); //END + scancode.insert(0x4e, rdev::Key::PageDown); //PAGE_DOWN + + scancode.insert(0x4f, rdev::Key::RightArrow); //ARROW_RIGHT + scancode.insert(0x50, rdev::Key::LeftArrow); //ARROW_LEFT + scancode.insert(0x51, rdev::Key::DownArrow); //ARROW_DOWN + scancode.insert(0x52, rdev::Key::UpArrow); //ARROW_UP + + scancode.insert(0x53, rdev::Key::NumLock); //NUM_LOCK + scancode.insert(0x54, rdev::Key::KpDivide); //NUMPAD_DIVIDE + scancode.insert(0x55, rdev::Key::KpMultiply); //NUMPAD_MULTIPLY + scancode.insert(0x56, rdev::Key::KpMinus); //NUMPAD_SUBTRACT + scancode.insert(0x57, rdev::Key::KpPlus); //NUMPAD_ADD + scancode.insert(0x58, rdev::Key::KpReturn); //NUMPAD_ENTER + + scancode.insert(0x59, rdev::Key::Kp1); //NUMPAD1 + scancode.insert(0x5a, rdev::Key::Kp2); //NUMPAD2 + scancode.insert(0x5b, rdev::Key::Kp3); //NUMPAD3 + scancode.insert(0x5c, rdev::Key::Kp4); //NUMPAD4 + scancode.insert(0x5d, rdev::Key::Kp5); //NUMPAD5 + scancode.insert(0x5e, rdev::Key::Kp6); //NUMPAD6 + scancode.insert(0x5f, rdev::Key::Kp7); //NUMPAD7 + scancode.insert(0x60, rdev::Key::Kp8); //NUMPAD8 + scancode.insert(0x61, rdev::Key::Kp9); //NUMPAD9 + scancode.insert(0x62, rdev::Key::Kp0); //NUMPAD0 + scancode.insert(0x63, rdev::Key::Dot); //NUMPAD_DECIMAL + + scancode.insert(0x64, rdev::Key::IntlBackslash); //INTL_BACKSLASH + scancode.insert(0x65, rdev::Key::Key); //CONTEXT_MENU + scancode.insert(0x66, rdev::Key::Key); //POWER + scancode.insert(0x67, rdev::Key::Key); //NUMPAD_EQUAL + + // scancode.insert(0x68, rdev::Key::Key); //F13 + // scancode.insert(0x69, rdev::Key::Key); //F14 + // scancode.insert(0x6a, rdev::Key::Key); //F15 + // scancode.insert(0x6b, rdev::Key::Key); //F16 + // scancode.insert(0x6c, rdev::Key::Key); //F17 + // scancode.insert(0x6d, rdev::Key::Key); //F18 + // scancode.insert(0x6e, rdev::Key::Key); //F19 + // scancode.insert(0x6f, rdev::Key::Key); //F20 + // + // scancode.insert(0x70, rdev::Key::Key); //F21 + // scancode.insert(0x71, rdev::Key::Key); //F22 + // scancode.insert(0x72, rdev::Key::Key); //F23 + // + // scancode.insert(0x73, rdev::Key::Key); //F24 + // scancode.insert(0x74, rdev::Key::Key); //OPEN + // + // scancode.insert(0x75, rdev::Key::Key); //HELP + // + // //scancode.insert(0x77, 0x0000); //SELECT + // + // scancode.insert(0x79, rdev::Key::Key); //AGAIN + // scancode.insert(0x7a, rdev::Key::Key); //UNDO + // scancode.insert(0x7b, rdev::Key::Key); //CUT + // scancode.insert(0x7c, rdev::Key::Key); //COPY + // scancode.insert(0x7d, rdev::Key::Key); //PASTE + // scancode.insert(0x7e, rdev::Key::Key); //FIND + // scancode.insert(0x7f, rdev::Key::Key); //VOLUME_MUTE + // + // scancode.insert(0x80, rdev::Key::Key); //VOLUME_UP + // scancode.insert(0x81, rdev::Key::Key); //VOLUME_DOWN + // scancode.insert(0x85, rdev::Key::Key); //NUMPAD_COMMA + // + // scancode.insert(0x87, rdev::Key::Key); //INTL_RO + // scancode.insert(0x88, rdev::Key::Key); //KANA_MODE + // scancode.insert(0x89, rdev::Key::Key); //INTL_YEN + // scancode.insert(0x8a, rdev::Key::Key); //CONVERT + // scancode.insert(0x8b, rdev::Key::Key); //NON_CONVERT + // scancode.insert(0x90, rdev::Key::Key); //LANG1 + // scancode.insert(0x91, rdev::Key::Key); //LANG2 + // scancode.insert(0x92, rdev::Key::Key); //LANG3 + // scancode.insert(0x93, rdev::Key::Key); //LANG4 + + scancode.insert(0xe0, rdev::Key::ControlLeft); //CONTROL_LEFT + scancode.insert(0xe1, rdev::Key::ShiftLeft); //SHIFT_LEFT + scancode.insert(0xe2, rdev::Key::Alt); //ALT_LEFT + scancode.insert(0xe3, rdev::Key::MetaLeft); //META_LEFT + scancode.insert(0xe4, rdev::Key::ControlRight); //CONTROL_RIGHT + scancode.insert(0xe5, rdev::Key::ShiftRight); //SHIFT_RIGHT + scancode.insert(0xe6, rdev::Key::Alt); //ALT_RIGHT + scancode.insert(0xe7, rdev::Key::MetaRight); //META_RIGHT + + + + + scancode +}; + +} \ No newline at end of file diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index dd03c2b3..43248c6e 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -128,26 +128,24 @@ impl MacroData { self.export_data(); } - // /// Extracts the data - // fn extract_triggers(&self){ - // let mut triggers: TriggerDataHash; - // - // //convert to enum of rdev - // - // - // for search in self.0{ - // for trig in search.macros { - // match trig.trigger { - // TriggerEventType::KeyPressEvent {data} => { - // // - // } - // } - // } - // } - // } + /// Extracts the data + fn extract_triggers(&self) { + let mut triggers: TriggerDataHash; + + //convert to enum of rdev + + + for search in &self.0 { + for trig in &search.macros { + match &trig.trigger { + TriggerEventType::KeyPressEvent { data } => {} + } + } + } + } } -// type TriggerDataHash = HashMap<>; +type TriggerDataHash = HashMap, Macro>; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Collection { From 533acfab444c627451b8dc5920ff11109b7f5b9e Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Sun, 30 Oct 2022 18:57:48 +0100 Subject: [PATCH 04/12] working on the translation table for keycodes Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/Cargo.lock | 16 ++++++++-------- src-tauri/src/hid_table.rs | 12 +++++++----- src-tauri/src/wooting_macros_library.rs | 9 +++++++-- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 9ce4bbcc..acc5ba78 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4192,14 +4192,14 @@ dependencies = [ name = "wooting-macros" version = "0.1.0" dependencies = [ - "halfbrown", - "idasen-cli", - "lazy_static", - "rdev", - "serde", - "serde_json", - "tauri", - "tauri-build", + "halfbrown", + "idasen-cli", + "lazy_static", + "rdev", + "serde", + "serde_json", + "tauri", + "tauri-build", ] [[package]] diff --git a/src-tauri/src/hid_table.rs b/src-tauri/src/hid_table.rs index 3398e99d..4c52bad1 100644 --- a/src-tauri/src/hid_table.rs +++ b/src-tauri/src/hid_table.rs @@ -5,7 +5,8 @@ use lazy_static::lazy_static; use rdev::Key; lazy_static! { -static ref SCANCODE_MAP: HashMap = { +#[derive(Debug, PartialEq)] +pub static ref SCANCODE_MAP: HashMap = { let mut scancode: HashMap = HashMap::new(); scancode.insert(0x04, rdev::Key::KeyA); //US_A scancode.insert(0x05, rdev::Key::KeyB); //US_B @@ -119,9 +120,9 @@ static ref SCANCODE_MAP: HashMap = { scancode.insert(0x63, rdev::Key::Dot); //NUMPAD_DECIMAL scancode.insert(0x64, rdev::Key::IntlBackslash); //INTL_BACKSLASH - scancode.insert(0x65, rdev::Key::Key); //CONTEXT_MENU - scancode.insert(0x66, rdev::Key::Key); //POWER - scancode.insert(0x67, rdev::Key::Key); //NUMPAD_EQUAL + scancode.insert(0x65, rdev::Key::Function); //CONTEXT_MENU + + // scancode.insert(0x67, rdev::Key::Key); //NUMPAD_EQUAL // scancode.insert(0x68, rdev::Key::Key); //F13 // scancode.insert(0x69, rdev::Key::Key); //F14 @@ -141,7 +142,8 @@ static ref SCANCODE_MAP: HashMap = { // // scancode.insert(0x75, rdev::Key::Key); //HELP // - // //scancode.insert(0x77, 0x0000); //SELECT + // scancode.insert(0x66, rdev::Key::Key); //POWER + // scancode.insert(0x77, 0x0000); //SELECT // // scancode.insert(0x79, rdev::Key::Key); //AGAIN // scancode.insert(0x7a, rdev::Key::Key); //UNDO diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index 43248c6e..c3891f06 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -10,7 +10,8 @@ use std::time::Duration; use rdev::{Button, Event, EventType, grab, Key, listen, simulate, SimulateError}; use serde::Serialize; -use crate::ApplicationConfig; +use crate::{ApplicationConfig, hid_table}; +use crate::hid_table::*; #[derive(Debug)] pub enum MacroType { @@ -138,7 +139,11 @@ impl MacroData { for search in &self.0 { for trig in &search.macros { match &trig.trigger { - TriggerEventType::KeyPressEvent { data } => {} + TriggerEventType::KeyPressEvent { data } => { + let temp = data.iter().for_each(|x| { + let temp2 = hid_table::SCANCODE_MAP[&x.keypress]; + }); + } } } } From d3f69e1f63bd3e1ce8251c922e1693474d0f8f09 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Sun, 30 Oct 2022 19:25:29 +0100 Subject: [PATCH 05/12] working on the translation table for keycodes Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/wooting_macros_library.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index c3891f06..86ac7ce8 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -21,7 +21,7 @@ pub enum MacroType { MultiLevel { data: Macro }, } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Hash, Eq)] struct KeyPress { keypress: u32, press_duration: Delay, @@ -131,7 +131,14 @@ impl MacroData { /// Extracts the data fn extract_triggers(&self) { - let mut triggers: TriggerDataHash; + let mut testing: HashMap, Macro> = HashMap::new(); + testing.insert(vec![], Macro { + name: "".to_string(), + sequence: vec![], + trigger: TriggerEventType::KeyPressEvent { data: vec![] }, + active: false, + }); + //convert to enum of rdev @@ -150,7 +157,6 @@ impl MacroData { } } -type TriggerDataHash = HashMap, Macro>; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Collection { From 9ad18426abeb2768743d797cfff1fa0fc23a542e Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Sun, 30 Oct 2022 19:49:35 +0100 Subject: [PATCH 06/12] working on the translation table for keycodes (still doesn't return the keycodes yet). Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/wooting_macros_library.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index 86ac7ce8..ad0a8ca7 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -131,7 +131,7 @@ impl MacroData { /// Extracts the data fn extract_triggers(&self) { - let mut testing: HashMap, Macro> = HashMap::new(); + let mut testing: TriggerHash = HashMap::new(); testing.insert(vec![], Macro { name: "".to_string(), sequence: vec![], @@ -157,6 +157,8 @@ impl MacroData { } } +///Hash list +type TriggerHash = HashMap, Macro>; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Collection { From 582603fab935dd5f865354fad30bf3b900bca842 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Mon, 31 Oct 2022 14:39:50 +0100 Subject: [PATCH 07/12] working on making the list for the triggers Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/wooting_macros_library.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index ad0a8ca7..38497574 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -131,13 +131,7 @@ impl MacroData { /// Extracts the data fn extract_triggers(&self) { - let mut testing: TriggerHash = HashMap::new(); - testing.insert(vec![], Macro { - name: "".to_string(), - sequence: vec![], - trigger: TriggerEventType::KeyPressEvent { data: vec![] }, - active: false, - }); + let mut trigger_hash_list: TriggerHash = HashMap::new(); //convert to enum of rdev @@ -147,13 +141,12 @@ impl MacroData { for trig in &search.macros { match &trig.trigger { TriggerEventType::KeyPressEvent { data } => { - let temp = data.iter().for_each(|x| { - let temp2 = hid_table::SCANCODE_MAP[&x.keypress]; - }); + trigger_hash_list.insert(data.clone(), trig.clone()); } } } } + println!("{:#?}", trigger_hash_list); } } @@ -276,6 +269,8 @@ pub fn run_this(config: &ApplicationConfig) { // Serve to the frontend. push_frontend_first(); + testing_macro_full.extract_triggers(); + //TODO: make this a grab instead of listen let (schan, rchan) = channel(); From eb36fe9e4d0741a55555be99a55831acee44ab55 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Mon, 31 Oct 2022 15:12:06 +0100 Subject: [PATCH 08/12] modified json to incorporate the vector nature Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/data_json.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src-tauri/data_json.json b/src-tauri/data_json.json index 98a2681e..35dbad38 100644 --- a/src-tauri/data_json.json +++ b/src-tauri/data_json.json @@ -4,7 +4,7 @@ "icon": "i", "macros": [ { - "name": "Paste", + "name": "TESTING THIS", "sequence": [ { "KeyPressEvent": { @@ -29,6 +29,10 @@ { "keypress": 14, "press_duration": 50 + }, + { + "keypress": 16, + "press_duration": 50 } ] } From 87cb14a9898eace73c3dce8b9b1fe6aaca9fe7a9 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Mon, 31 Oct 2022 17:57:02 +0100 Subject: [PATCH 09/12] created the hashtable with a reference to Macros to check against. Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/hid_table.rs | 2 +- src-tauri/src/main.rs | 18 +-- src-tauri/src/wooting_macros_library.rs | 141 +++++++----------------- 3 files changed, 49 insertions(+), 112 deletions(-) diff --git a/src-tauri/src/hid_table.rs b/src-tauri/src/hid_table.rs index 4c52bad1..5a757eb6 100644 --- a/src-tauri/src/hid_table.rs +++ b/src-tauri/src/hid_table.rs @@ -182,4 +182,4 @@ pub static ref SCANCODE_MAP: HashMap = { scancode }; -} \ No newline at end of file +} diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6bd82c8c..753e34a2 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -28,15 +28,15 @@ pub struct ApplicationConfig { } fn main() { - // tauri::Builder::default() - // // This is where you pass in your commands - // .invoke_handler(tauri::generate_handler![ - // export_frontend, - // import_frontend, - // push_frontend_first - // ]) - // .run(tauri::generate_context!()) - // .expect("error while running tauri application"); + tauri::Builder::default() + // This is where you pass in your commands + .invoke_handler(tauri::generate_handler![ + export_frontend, + import_frontend, + push_frontend_first + ]) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); let mut config: ApplicationConfig = ApplicationConfig { use_input_grab: false, diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index 38497574..78fc7821 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -55,9 +55,7 @@ pub enum ActionEventType { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum TriggerEventType { - KeyPressEvent { - data: Vec, - }, + KeyPressEvent { data: Vec }, } #[derive(Debug, Clone)] @@ -124,34 +122,32 @@ impl MacroData { /// Imports data from the frontend (when updated) to update the background data structure /// This overwrites the datastructure - pub fn import_data(&mut self, input: MacroData) { + pub fn import_data(&mut self, input: MacroData) -> TriggerHash { *self = input; self.export_data(); + self.extract_triggers() } /// Extracts the data - fn extract_triggers(&self) { + fn extract_triggers(&self) -> TriggerHash { let mut trigger_hash_list: TriggerHash = HashMap::new(); - - //convert to enum of rdev - - for search in &self.0 { for trig in &search.macros { match &trig.trigger { TriggerEventType::KeyPressEvent { data } => { - trigger_hash_list.insert(data.clone(), trig.clone()); + trigger_hash_list.insert(data.clone(), &trig); } } } } - println!("{:#?}", trigger_hash_list); + + trigger_hash_list } } ///Hash list -type TriggerHash = HashMap, Macro>; +type TriggerHash<'a> = HashMap, &'a Macro>; #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct Collection { @@ -165,100 +161,39 @@ pub struct Collection { ///Main loop for now (of the library) /// * `config` - &ApplicationConfig from the parsed JSON config file of the app. pub fn run_this(config: &ApplicationConfig) { - // let mut testing_macro_full: MacroData = MacroData { - // 0: vec![ - // Collection { - // name: "Main group".to_string(), - // icon: 'i'.to_string(), - // macros: vec![Macro { - // name: "Paste".to_string(), - // sequence: vec![ - // ActionEventType::KeyPressEvent { - // data: KeyPress { - // keypress: 12, - // - // press_duration: 50, - // }, - // }, - // ActionEventType::KeyPressEvent { - // data: KeyPress { - // keypress: 13, - // - // press_duration: 50, - // }, - // }, - // ], - // trigger: TriggerEventType::KeyPressEvent { - // data: vec![KeyPress { - // keypress: 14, + // let mut incoming_test: MacroData = MacroData { + // 0: vec![Collection { + // name: "LOL".to_string(), + // icon: 'i'.to_string(), + // macros: vec![Macro { + // name: "Newer string".to_string(), + // sequence: vec![ + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 12, // // press_duration: 50, - // }], - // }, - // active: true, - // }], - // active: true, - // }, - // Collection { - // name: "Fun macro group".to_string(), - // icon: 'i'.to_string(), - // macros: vec![ - // Macro { - // name: "Havo".to_string(), - // sequence: vec![ - // ActionEventType::KeyPressEvent { - // data: KeyPress { - // keypress: 14, - // - // press_duration: 50, - // }, - // }, - // ActionEventType::KeyPressEvent { - // data: KeyPress { - // keypress: 13, - // - // press_duration: 50, - // }, - // }, - // ActionEventType::KeyPressEvent { - // data: KeyPress { - // keypress: 12, - // - // press_duration: 50, - // }, - // }, - // ], - // trigger: TriggerEventType::KeyPressEvent { - // data: vec![KeyPress { - // keypress: 22, - // - // press_duration: 50, - // }], // }, - // active: true, // }, - // Macro { - // name: "Svorka".to_string(), - // sequence: vec![ActionEventType::KeyPressEvent { - // data: KeyPress { - // keypress: 23, + // ActionEventType::KeyPressEvent { + // data: KeyPress { + // keypress: 13, // - // press_duration: 50, - // }, - // }], - // trigger: TriggerEventType::KeyPressEvent { - // data: vec![KeyPress { - // keypress: 24, - // - // press_duration: 50, - // }], + // press_duration: 50, // }, - // active: true, // }, // ], + // trigger: TriggerEventType::KeyPressEvent { + // data: vec![KeyPress { + // keypress: 14, + // + // press_duration: 50, + // }], + // }, // active: true, - // }, - // ], + // }], + // active: true, + // }], // }; //testing_macro_full.export_data(); @@ -269,8 +204,13 @@ pub fn run_this(config: &ApplicationConfig) { // Serve to the frontend. push_frontend_first(); - testing_macro_full.extract_triggers(); + // Get the triggers linked correctly + let triggers = testing_macro_full.export_data(); + + //Print for a check (triggers) + println!("{:#?}", triggers); + //================================================== //TODO: make this a grab instead of listen let (schan, rchan) = channel(); @@ -306,9 +246,7 @@ pub fn run_this(config: &ApplicationConfig) { println!("MB Released:{:?}", s) } EventType::MouseMove { x, y } => (), - EventType::Wheel { delta_x, delta_y } => { - - } + EventType::Wheel { delta_x, delta_y } => {} } } events.pop(); @@ -316,7 +254,6 @@ pub fn run_this(config: &ApplicationConfig) { //TODO: Make a translation table to a hashmap from a keycode HID compatible -> library rdev enums. } - fn send(event_type: &EventType) { let delay = time::Duration::from_millis(20); match simulate(event_type) { From f119f19d70232b9b3e54a0ccf53449f889c8c7e1 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Mon, 31 Oct 2022 17:58:42 +0100 Subject: [PATCH 10/12] created the hashtable with a reference to Macros to check against. Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/wooting_macros_library.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index 78fc7821..2bc0408a 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -213,6 +213,10 @@ pub fn run_this(config: &ApplicationConfig) { //================================================== //TODO: make this a grab instead of listen + //TODO: try to make this interact better (cleanup the code a bit) + //TODO: make the pressed keys vector and compare to the hashmap + //TODO: try to execute the macros in order (make the executor) + //TODO: async the executor of the presses let (schan, rchan) = channel(); let _listener = thread::spawn(move || { listen(move |event| { From 19192e421d2be509536119e49bc886b2dadf858f Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Mon, 31 Oct 2022 17:58:52 +0100 Subject: [PATCH 11/12] created the hashtable with a reference to Macros to check against. Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/wooting_macros_library.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index 2bc0408a..9a36668c 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -217,6 +217,7 @@ pub fn run_this(config: &ApplicationConfig) { //TODO: make the pressed keys vector and compare to the hashmap //TODO: try to execute the macros in order (make the executor) //TODO: async the executor of the presses + // let (schan, rchan) = channel(); let _listener = thread::spawn(move || { listen(move |event| { From f636411e1c3a80318c0da06f629d2ed184d52a16 Mon Sep 17 00:00:00 2001 From: David M <1900179+medzernik@users.noreply.github.com> Date: Mon, 31 Oct 2022 18:00:28 +0100 Subject: [PATCH 12/12] created the hashtable with a reference to Macros to check against. Signed-off-by: David M <1900179+medzernik@users.noreply.github.com> --- src-tauri/src/wooting_macros_library.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-tauri/src/wooting_macros_library.rs b/src-tauri/src/wooting_macros_library.rs index 9a36668c..3b03c128 100644 --- a/src-tauri/src/wooting_macros_library.rs +++ b/src-tauri/src/wooting_macros_library.rs @@ -205,7 +205,7 @@ pub fn run_this(config: &ApplicationConfig) { push_frontend_first(); // Get the triggers linked correctly - let triggers = testing_macro_full.export_data(); + let triggers = testing_macro_full.extract_triggers(); //Print for a check (triggers) println!("{:#?}", triggers);