Git Product home page Git Product logo

Comments (4)

rodrigocfd avatar rodrigocfd commented on June 16, 2024 1

Yep, that's it.

Can you check now?

from winsafe.

makindotcc avatar makindotcc commented on June 16, 2024 1

It's working :) thank you, this crate saves so much pain.

from winsafe.

rodrigocfd avatar rodrigocfd commented on June 16, 2024

GetAsyncKeyState returns multiple key states: hold, was pressed after previous call to GetAsyncKeyState ("However, you should not rely on this last behavior" so I don't know if this is actually important in "safe" crate

I'd say this is important not only in the context of a safe crate: even in C++ code we shouldn't rely on that.

then most significant bit should be checked instead rather than comparing it with 0

You are correct. I fixed the implementation with example given in the documentation itself.

from winsafe.

makindotcc avatar makindotcc commented on June 16, 2024

I think it should be & 0x8000 != 0 or just < 0 (since its the sign bit), because with current version it will return true even if key is not held anymore (but was held in previous GetAsyncKeyState call):

use std::thread::sleep;
use std::time::Duration;
use winapi::um::winuser::{GetAsyncKeyState, VK_CONTROL};

fn main() {
    println!("Hello, world!");
    loop {
        sleep(Duration::from_secs(5));
        println!("state: {:?}", unsafe { GetAsyncKeyState(VK_CONTROL) & 0x01 });
    }
}

Documentation example shows key press usage, it is kinda different - it reacts for key down and up.

idea64_6kzQ7gcIYb.mp4

from winsafe.

Related Issues (20)

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.