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

How to use InputInjector #316

Closed
jcdickinson opened this issue Aug 21, 2020 · 2 comments
Closed

How to use InputInjector #316

jcdickinson opened this issue Aug 21, 2020 · 2 comments
Labels
question Further information is requested

Comments

@jcdickinson
Copy link

I'm trying to use InputInjector and this is as much as I have managed:

use winrt::import;

import!(
    dependencies
        os
    types
        windows::ui::input::preview::injection::InputInjector
        windows::system::VirtualKey
);

use std::time::Duration;
use windows::ui::input::preview::injection::{InjectedInputKeyboardInfo, InputInjector};
use winrt::Array;

fn main() -> winrt::Result<()> {
    let injector = InputInjector::try_create()?;

    loop {
        let info = InjectedInputKeyboardInfo::new()?;
        info.set_virtual_key(9)?;
        let mut arr = Array::with_len(1);
        arr[0] = info;
        injector.inject_keyboard_input(winrt::Param::Owned(arr))?;
        std::thread::sleep(Duration::from_secs(5));
    }
}

It fails to compile with this error (on the inject_keyboard_input line):

the trait `winrt::AbiTransferable` is not implemented for `winrt::Array<windows::ui::input::preview::injection::InjectedInputKeyboardInfo>`

I have also tried Param::Borrowed. Any suggestions?

@jcdickinson
Copy link
Author

Related: I can't figure out how to extract the constant value from VirtualKey - if that is at all possible.

@kennykerr
Copy link
Collaborator

The inject_keyboard_input method is expecting a collection interface (IIterable<T>) rather than an array. That explains the parameter mismatch. Unfortunately, Rust/WinRT doesn't yet support implementing polymorphic collections. I'm working on that now. #81

@kennykerr kennykerr added the question Further information is requested label Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants