Code Monkey home page Code Monkey logo

device_query's People

Contributors

abdillah avatar barkera avatar chris--b avatar coderedart avatar dilawar avatar horki avatar lemunozm avatar macbrayne avatar notdanilo avatar nycrat avatar orhun avatar ostrosco avatar powerory avatar riizade avatar segeljakt avatar sn99 avatar tcrouch avatar tehmoros avatar zeon256 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

device_query's Issues

Right shift/control/etc. get reported as left buttons on MacOS

From a different issue:

When recording keystrokes via dq, when encountering these keys (SHIFT、OPTION、CONTROL), it will be recorded as 'left' regardless of whether the press is 'left' or 'right'.

This only appears to be happening on MacOS. We'll need to figure out if this is a device_query or dependency issue.

Add Wayland Support

My program gives me this error

Maximum number of clients reached. Thread 'main' panicked at 'Could not connect to a X display', /home/helium/.cargo/registry/src/github.com-1ecc6299db9ec823/device_query-0.2.8/src/linux/mod.rs:26:17

And i'm running on Wayland so I suspect that it doesn't support Wayland at the moment. Any plans on adding Wayland support?

Numpad implementation issues

I'm currently implementing Numpad support but there are some keys which technically can be found twice on a standard keyboard:

  • PLUS vs Numpad PLUS
  • MINUS vs Numpad MINUS

as well as overlapping keys:

  • SHIFT+7 vs Numpad DIVIDE
  • SHIFT+8 vs Numpad MULTIPLY
  • COMMA or DOT (dependent on the locale / keyboard layout(!)) vs Numpad SEPERATOR

Should nearly identical keys be merged or this too high-level for this crate?

[request]Add priorKey().

priorKey(): The name of the last key which was down prior to the most recent key-down or key-release, or blank if no applicable key-press can be found in the key history.Just like Autohotkey.

On MacOS, only seems to show mod keys (ctrl, meta, shift)

Code taken from here (https://stackoverflow.com/questions/35671985/how-do-i-get-keyboard-input-without-the-user-pressing-the-enter-key)

use device_query::{DeviceQuery, DeviceState, Keycode};

fn main() {
    let device_state = DeviceState::new();
    loop {
        let keys: Vec<Keycode> = device_state.get_keys();
        for key in keys.iter() {
            println!("Pressed key: {:?}", key);
        }
    }
}

None of my character inputs are recognized. Only stuff like LControl or BackSpace

Arrow keys support

Hi!
I was wondering about the arrow keys support. Is it missing for some reason in special? Is it a future work?

Support for wayland onn linux

Hello,

as wayland is now getting the default window manager on several linux distributions, I would very like to see support for it in this lib.
In case you need support in testing I can try to help.

about the closure in `on_key_down`(or `on_key_up`)

Hi, thanks for your awesome library.

I'm engaged in front-end development, and recently I'm using tauri to make an app that records keystrokes (and want to use enigo for autoplay),

But I ran into a problem, in your example (event_based_print_keys.rs),
You use println! to print directly to the console, but I'd like to be able to log to a vector for other uses.

However, because on_key_down's parameter callback is of type Fn instead of FnMut, I cannot modify the outer vector.

Is there any good workaround please, I'm wondering if using FnMut here will cause some side effects.
I may not have learned enough about rust, I hope you can point out where I am wrong.

Thanks again, this library is very helpful for my development.

  • Here's how what I want to do looks like, but it doesn't work
pub struct KeyboardEv {
    code: Keycode,
    press: bool,
    timestamp: u128,
}

pub struct KeyboardRecorder {
    ev_queue: Vec<KeyboardEv>,
}

impl KeyboardRecorder {
    pub fn new() -> Self {
        KeyboardRecorder {
            ev_queue: vec![],
        }
    }

    pub fn start_record(&mut self) {
        // instance
        let device_state = DeviceState::new();
        // record start time as zero
        let mut timeline = Instant::now();

        // record press
        let _guard = device_state.on_key_down(|key| {
            println!("down: {:#?}", key);

            let keyCode = key.clone();
            let time_from_zero = timeline.elapsed().as_millis();

            // ▲ i`d like to save custom event record in an outer vector
            self.ev_queue.push(KeyboardEv {
                code: keyCode,
                press: true,
                timestamp: time_from_zero,
            });
        });
        // record release
        // let _guard = device_state.on_key_up(|key| {
        //     println!("up: {:#?}", key);
        // });

        loop {}
    }
}

device_query not registering some keys

I'm running this code:

use device_query::{DeviceQuery, DeviceState, Keycode};

fn main() {
    let device_state = DeviceState::new();
    loop {
        let keys: Vec<Keycode> = device_state.get_keys();
        for key in keys.iter() {
            println!("Pressed key: {:?}", key);
        }
    }
}

There are several keys that when pressed don't trigger a 'Pressed Key ...' message. They include arrowkeys, -, +, `, backspace, and a couple others. Any idea what's going on here?

I'm running this app using cargo run from powershell/windows terminal on Windows 10.

Key codes vs Scan codes

This project currently supports a subset of ASCII and most of the modifier keys like CTRL and SHIFT. But on other keyboard layouts it provides incorrect mappings, e.g. QWERTZ ö translates to Grave instead of the umlaut (this is mentioned in the project
files). This is to be expected as i.e. the Win32 API only labels them as "OEM keys", the linux kernel on the other hand labels this key as GRAVE instead.
However if the mappings are US-QWERTY only they are currently inconsistent as the crate/Windows does translate the ASCII keys (like z vs y in QWERTZ) between locales (at least on windows) due to windows probably pre-processing the keys (I couldn't find any information online on this).
I have not researched the APIs as to why they label it differently but this problem on begs the question:

How "high-level" is this crate? Should this crate reporting the key position or the user facing value of the key? If yes, should or can they be localized?

Cargo deny warns against the dependency input-event-codes GPLv2 license as copyleft

device_query uses input-event-codes crate as dependency, and has MIT as the license.

but input-event-codes has its license set to "GPL-2.0-only" which is AFAICT copy-left which would mean device_query (and crates that depend on it) would get infected with that license too as all of us use static linking against that crate (and its source).

I was just setting up deny.toml for my project and this issue popped up.

Possible keyboard layout mess on linux

When trying to input a '@' key using a German QWERTZ keyboard (so ALTGR+Q), the crate outputs "Key2" instead of L-CONTROL+R-ALT+Q. This is probably due to Linux/X11 translating the keycodes into a american keyboard layout in which the number row 2 key is used for typing '@'. In contrast on Windows the correct key is output.
The same basic problem applies to the key combination for 'µ' using ALTGR+M with no keycode whatsoever being output.

I suppose the issue doesn't lie with this crate but the way the keycodes are obtained. Are there any different less problematic methods of obtaining keycodes? If not, what can be done to mitigate this problem?

(Used the print_keycode example for testing)

question about the `CallbackGuard`

sorry bro, i`m back again. /(ㄒoㄒ)/~~

Recently i`m writing a node-addon for my electron app to listen some hotkey events (such as ctrl+c for copy).
I use the napi library (https://github.com/napi-rs/napi-rs) to implement the transition from rust to node.

But I encountered a little problem when listening to the button. As written in your example,

image

as long as _guard is alive, the listen will always be valid. My idea is to assign the guard returned by the function to a member of the struct so It can be held for a long time, but I don't know what type of this member should be defined, can you give me some help ┭┮﹏┭┮

image
image

Cannot query keyboard state in linux terminal

Hi, I'm trying to use this crate in a TUI I'm developing as a way to detect key-up events but it seems to not detect anything when the terminal is in focus on Linux. Actually, it seems to not work at all unless I have certain other applications in focus--seemingly ones that aren't capturing text input. I'm not sure how to proceed.

Ubuntu 22.04.1 LTS
device_query v1.1.1

Unable to detect Alphanumeric keys in MacOS 11.2.2

My computer is a MacBook Pro running the most recent MacOS (11.2.2). It appears that get_keys() is not picking up when alphanumeric keys, or the spacebar are pressed. Other keys (tab, shit, ctrl, etc.) are detected. From talking with friends, they are experiencing the same issue, and code that does not work on my MacBook runs without issue when performed on Windows.

Wayland support?

Currently, another choice for linux user is that, using wayland rather than x11.

But as I tried device_query on my wayland based linux, the demo always returns

Current Mouse Coordinates: (94, 1035)
Is A pressed? false

It seems that there is no support for wayland now
Is it possible to add wayland support?

Can not use with GTK

I have tried with some basic GTK window. I am getting a Segmentation fault (core dumped) error.

Operating system: Linux

extern crate gtk;
extern crate device_query;

use device_query::{DeviceState};
use gtk::prelude::*;

fn main(){
    if let Err(_) = gtk::init() {
        panic!("UIError");
    }

    let window = gtk::Window::new(gtk::WindowType::Toplevel);
    window.set_title("First GTK+ Program");
    window.set_border_width(10);
    window.set_position(gtk::WindowPosition::Center);
    window.set_default_size(350, 70);
    let button = gtk::Button::new_with_label("Click me!");
    window.add(&button);

    let device_state = DeviceState::new();

    window.show_all();
    gtk::main();
}

Dependencies

device_query = "0.2.3"
gtk = "0.8.1"

Alert developers on macOS when the app lacks permissions

On macOS, accessibility permissions are required before this library will function at all. See here. This is already documented in the README, but to make it easier on developers using this crate it would be nice if a message could be logged when the app doesn't have permissions. The API could also do this check and expose it as a function somewhere, so that consumers of the crate can write it to their own popup or messaging for their users.

Here's the example from the README, modified to show an example API:

let device_state: DeviceState = match DeviceState::new() {
    Ok(device) => device,
    Err(DeviceError::InsufficientPermissions) => {
            message_box("Please enable Accessibility Permissions");
            return;
    },
    Err(e) => panic!("{}", e),
};

// The rest of the example is unchanged 
let mouse: MouseState = device_state.get_mouse();
println!("Current Mouse Coordinates: {:?}", mouse.coords);
let keys: Vec<Keycode> = device_state.get_keys();
println!("Is A pressed? {}", keys.contains(Keycode::A));

I have no idea if Apple's APIs will allow this or not, so this is just spit balling to show usage. Once we know this can work, we can iterate on what a useful API would actually look like.

This commit in dteoh/SlowQuitApps added a popup dialog and is probably a good starting place to figure out how to include this kind of check.

"Maximum number of clients reached" when creating multiple DeviceState

image

I have this very simple function that is meant to run multiple times. About two hundred calls into this function, I have the following error:
image
Pointing me to this line

I suspect it's because I am creating multiple DeviceState, and they are not having enough time to close (?)

This is on Manjaro 21 XFCE.

P.S. My original problem is that I need to query the mouse coordinates, but I could not make the DeviceState into a static (it does not implement Sync), so I was creating one locally every time. I appreciate Rust-specific suggestions for solving this particular problem too (How to make a unique instance of DeviceState where I can query the coords from?)

Error to compile x11 dependency

Hi @ostrosco,

Compiling your library in a clean ubuntu18, I got the following error related to your x11 dependency:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Failure { command: "\"pkg-config\" \"--libs\" \"--cflags\" \"x11\" \"x11 >= 1.4.99.1\"", output: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Package x11 was not found in the pkg-config search path.\nPerhaps you should add the directory containing `x11.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'x11\' found\nPackage x11 was not found in the pkg-config search path.\nPerhaps you should add the directory containing `x11.pc\'\nto the PKG_CONFIG_PATH environment variable\nNo package \'x11\' found\n" } }', src/libcore/result.rs:1188:5

After investigating, I found that it is due to the leak of the x11 development libraries in the system, needed to compile x11.

In ubuntu it can be easily installed with the following command:

sudo apt install libx11-dev

Maybe it can be useful to add this dependency under a "dependencies" section as part of the readme.

Regards!

Support for KEY_PROGs

Wanted ask if you can add support for KEY_PROG1,2,3,4?
I am creating an issue because I am not sure how would that work on Windows/MacOS, on Linux that is straight forward, only need to add them to the Keycode enum and too kernel_key_to_keycode
For me it would be perfectly fine to have those keys only working on Linux, I am working on a program for doing some power management on my laptop and it has two nice keys dedicated to it with emit KEY_PROG1 and KEY_PROG2.

Would be fine to add those keys but mark them with #[cfg(target_os = "linux")], in this way when someone would try to use them on MacOS/Windows it would give a compiler error?

Of course is someone finds what codes are for those keys on Windows/MacOS then they could be add too, but I am even not sure if they exist on those systems.

High CPU usage

(Sorry, I'm completely new to desktop programming. Maybe it's not an issue.)

I ran the code from examples/event_based_print_keys.rs and found that the app uses 300% CPU (on Mac). As I guess, 100% is taken by loop {}, but is it normal that it uses 200% more?

Misleading docs.rs documentation for methods

some methods noted in https://docs.rs/device_query/1.1.1/device_query/ are not implemented, is this planned in the future or do we have to implement listeners on our own?

e.g:

let device_state = DeviceState::new();

 let _guard = device_state.on_mouse_move(|position| {
    println!("Mouse position: {:#?}", position);
 });

no method named `on_mouse_move` found for struct `device_query::DeviceState` in the current scope

Not functional on Wayland

attempting to compile a project with this crate on wayland returns the error

Perhaps you should add the directory containing `x11.pc' to the PKG_CONFIG_PATH environment variable
Package 'x11', required by 'virtual:world', not found```

Scrolling support

Just a feature request to include scrolling in the mouse state if possible

crate fails to install

When I try to use the program listed in the README and run cargo build it fails with this error:

 Compiling device_query v0.1.3
error[E0601]: `main` function not found in crate `build_script_build`
  --> /Users/rj/.cargo/registry/src/github.com-1ecc6299db9ec823/device_query-0.1.3/build.rs:1:1
   |
1  | / extern crate pkg_config;
2  | |
3  | | #[cfg(target_os = "windows")]
4  | | fn main() {}
...  |
39 | |     }
40 | | }
   | |_^ consider adding a `main` function to `/Users/rj/.cargo/registry/src/github.com-1ecc6299db9ec823/device_query-0.1.3/build.rs`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0601`.
error: could not compile `device_query`.

To learn more, run the command again with --verbose.

I am on Macos, and looking at the file in question, it doesn't look like there's a #[cfg(target_os = "macos")].

I am able to build your repo just fine by cloning it and building it a temp directory.

working through ssh

i I made a mwe on windows and it works fine. However, now I need to upload the code to raspberry pi. I access it through ssh (using mobaxterm which has a x server). But it does not recognise the keys through the ssh, and if i plug in a keyboard directly to the pi, it does not register the keys. any ideas?

segmentation fault

Hi, i receive a seg fault when trying to run an example to get keypresses. If you are able to lend some advice that would be awesome. thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.