mirror of
https://codeberg.org/icewind/shortcutd.git
synced 2026-06-03 17:24:08 +02:00
allow some bare shortcuts, example work
This commit is contained in:
parent
60465ac735
commit
42237bc965
9 changed files with 232 additions and 63 deletions
|
|
@ -1,19 +1,26 @@
|
|||
use shortcutd::{ShortcutClient};
|
||||
use std::error::Error;
|
||||
use clap::Parser;
|
||||
use evdev_shortcut::Shortcut;
|
||||
use futures::pin_mut;
|
||||
use futures::stream::iter;
|
||||
use futures::StreamExt;
|
||||
use shortcutd::ShortcutClient;
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Shortcut to listen to
|
||||
shortcuts: Vec<Shortcut>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args = Args::parse();
|
||||
let client = ShortcutClient::new().await?;
|
||||
|
||||
let streams = [
|
||||
Box::pin(client.register("<Ctrl>-KeyM".parse()?).await?),
|
||||
Box::pin(client.register("<Ctrl><Alt>-KeyO".parse()?).await?),
|
||||
];
|
||||
|
||||
let stream = iter(streams).flatten_unordered(None);
|
||||
let stream = iter(args.shortcuts)
|
||||
.then(|shortcut| async { Box::pin(client.listen(shortcut).await.unwrap()) })
|
||||
.flatten_unordered(None);
|
||||
|
||||
pin_mut!(stream);
|
||||
|
||||
|
|
|
|||
19
client/examples/simple.rs
Normal file
19
client/examples/simple.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
use futures::{pin_mut, StreamExt};
|
||||
use shortcutd::{Shortcut, ShortcutClient};
|
||||
use std::error::Error;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let client = ShortcutClient::new().await?;
|
||||
|
||||
let shortcut: Shortcut = "<Ctrl><Alt>-KeyO".parse()?;
|
||||
|
||||
let stream = client.listen(shortcut).await?;
|
||||
|
||||
pin_mut!(stream);
|
||||
|
||||
while let Some(event) = stream.next().await {
|
||||
println!("{} {}", event.shortcut, event.state.as_str());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue