Skip to content

Commit

Permalink
update to latest enigo
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Nov 20, 2023
1 parent eab1c6d commit 15e6398
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
35 changes: 32 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tauri-build = { version = "1.4", features = [] }

[dependencies]
tauri = { version = "1.4", features = ["shell-open", "devtools"] }
enigo = { version = "0.1.3" }
enigo = { version = "0.2.0-rc2" }


[target.'cfg(any(windows, target_os = "macos"))'.dependencies]
Expand Down
48 changes: 24 additions & 24 deletions desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]


#[cfg(any(windows, target_os = "macos"))]
use window_shadows::set_shadow;

use enigo::{Direction, Enigo, Key, Keyboard, Settings};
use tauri::Manager;
use enigo::*;

#[tauri::command]
async fn press(key: String) -> Result<(), String> {
let mut controller = Enigo::new();
let mut enigo = Enigo::new(&Settings::default()).unwrap();

match key.as_str() {
"VOL_UP" => {
controller.key_down(Key::VolumeUp);
},
enigo.key(Key::VolumeUp, Direction::Click).unwrap();
}
"VOL_DN" => {
controller.key_down(Key::VolumeDown);
},
enigo.key(Key::VolumeDown, Direction::Click).unwrap();
}
"PG_UP" => {
controller.key_down(Key::PageUp);
},
enigo.key(Key::PageUp, Direction::Click).unwrap();
}
"PG_DN" => {
controller.key_down(Key::PageDown);
},
enigo.key(Key::PageDown, Direction::Click).unwrap();
}
"F5" => {
controller.key_down(Key::F5);
},
enigo.key(Key::F5, Direction::Click).unwrap();
}
"ESC" => {
controller.key_down(Key::Escape);
enigo.key(Key::Escape, Direction::Click).unwrap();
}
_ => {}
}
Expand All @@ -37,15 +37,15 @@ async fn press(key: String) -> Result<(), String> {

fn main() {
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();
#[cfg(any(windows, target_os = "macos"))]
set_shadow(&window, true).unwrap();
.setup(|app| {
let window = app.get_window("main").unwrap();

#[cfg(any(windows, target_os = "macos"))]
set_shadow(&window, true).unwrap();

Ok(())
})
.invoke_handler(tauri::generate_handler![press])
.run(tauri::generate_context!())
.expect("error while running tauri application");
Ok(())
})
.invoke_handler(tauri::generate_handler![press])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

0 comments on commit 15e6398

Please sign in to comment.