InputBot icon indicating copy to clipboard operation
InputBot copied to clipboard

Media keys don't work on Windows

Open skkeeper opened this issue 5 years ago • 3 comments

Hi, first of all thanks for your work on this. I've starting to mess a bit with Rust and was trying to simulate the MEDIA KEY PLAY/PAUSE press on Windows. I might be messing something up but this is the code I'm trying to use as an example:

use inputbot::{*};

fn main() {
    KeybdKey::OtherKey(0xB3).press();
}

Running this code seems to cause the "g" key to be pressed instead of VK_MEDIA_PLAY_PAUSE.

I've noticed this behaviour on similar crates so this might be an issue of the windows api.

Thanks

skkeeper avatar Oct 23 '20 00:10 skkeeper

@skkeeper I am not sure, but media keys may require for KEYEVENTF_EXTENDEDKEY to be specified as an additional flag in the KEYBDINPUT struct https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-keybdinput.

I am not sure how to best implement this in InputBot. I will take a deeper look.

obv-mikhail avatar Oct 31 '20 05:10 obv-mikhail

Another thought is that on Windows InputBot currently uses scan codes instead of VK codes, so 0xB3 would probably not be the right code. Maybe we should switch from scan codes to the VK codes..

obv-mikhail avatar Oct 31 '20 05:10 obv-mikhail

@obv-mikhail I have tried both scan codes and vk codes for the LAlt, as both decimal and hex numbers (number is 0x38 scan.) I cannot get OtherKey to work for anything, even keys that are already defined in the enum (passing in the usize manually). I notice LAlt exists on dev branch, but I am not contributing and will be using your actions branch.

I am on windows.

(Specifically the bind function).

chaslain avatar Feb 21 '23 15:02 chaslain