Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include scan code when simulating keyboard events on Windows #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

isaackd
Copy link

@isaackd isaackd commented Sep 12, 2023

While trying to get keypresses detected by Factorio I noticed it would only work when the proper scan codes are included in the call to SendInput.

This should also fix #73 according to rustdesk/rustdesk#366 (comment).

I'm not super familiar with the Windows API and came across a more complete-looking implementation at https://github.com/fufesou/rdev/blob/560eb62adfaa1e53b77d80800904b3241812e284/src/windows/simulate.rs#L116-L134, but maybe this PR is a good starting point?

@Narsil
Copy link
Owner

Narsil commented Sep 21, 2023

@isaackd very nice.

Not having a windows machine at hand (only remote ones which don't make testing this easy), I would love if someone could confirm/infirm this PR is indeed working.

@Narsil
Copy link
Owner

Narsil commented Sep 21, 2023

The other PR looks more complete, but thereś a lot of weird values and switches going on, which are probably a tiny bit too platform specific.

Either windows document those values (and they are usually in the lib as flags) and we need to link that, or they are not and I wouldn't include them.

Your PR looks better imo.

use winapi::um::winuser::{MapVirtualKeyA, MAPVK_VK_TO_VSC};

pub fn scan_from_code(code: WORD) -> Option<WORD> {
let scan = unsafe { MapVirtualKeyA(code as u32, MAPVK_VK_TO_VSC) } as WORD;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be either MapVirtualKey or MapVirtualKeyW instead (source)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Virtualbox can't receive keyboard
3 participants