begin minimal keyboard simulation
This commit is contained in:
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
@@ -1838,11 +1838,13 @@ name = "keeb"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"enigo",
|
||||
"raw-window-handle",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tauri-plugin-opener",
|
||||
"x11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -23,6 +23,8 @@ tauri-plugin-opener = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
enigo = "0.6.1"
|
||||
x11 = { version = "2.21.0", features = ["xlib"] }
|
||||
raw-window-handle = "0.6.2"
|
||||
|
||||
[profile.dev]
|
||||
incremental = true # Compile your binary in smaller steps.
|
||||
|
||||
@@ -1,12 +1,44 @@
|
||||
use enigo::{Direction::Click, Enigo, Key, Keyboard, Settings};
|
||||
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle, WindowHandle};
|
||||
use std::ptr;
|
||||
use tauri::Manager;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
let mut enigo = Enigo::new(&Settings::default()).unwrap();
|
||||
enigo.key(Key::Unicode('a'), Click);
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
let window = app.get_webview_window("main").unwrap();
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use x11::xlib;
|
||||
// raw X11 pointers here
|
||||
unsafe {
|
||||
let handle = window.raw_window_handle();
|
||||
if let Ok(RawWindowHandle::Xlib(h)) = handle {
|
||||
let display = xlib::XOpenDisplay(ptr::null());
|
||||
if !display.is_null() {
|
||||
let hints = xlib::XAllocWMHints();
|
||||
if !hints.is_null() {
|
||||
(*hints).flags = xlib::InputHint;
|
||||
(*hints).input = 0; // Set input hint to False
|
||||
xlib::XSetWMHints(display, h.window, hints);
|
||||
xlib::XFree(hints as *mut _);
|
||||
}
|
||||
xlib::XCloseDisplay(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.run(tauri::generate_context!())
|
||||
|
||||
Reference in New Issue
Block a user