MediatedCommunications / WindowsInput

Capture and Simulate Keyboard and Mouse Input
MIT License
115 stars 17 forks source link

Random keystrokes #8

Closed C1rdec closed 4 years ago

C1rdec commented 4 years ago

Some of my users are experiencing random keystrokes after my application is running for a good amount of times. (A restart of the application fix the issue)

Here's how I handle the EventBuilder

protected async Task SendCommand(string command, bool setForegound = true)
{
    var eventBuilder = Simulate.Events();
    eventBuilder.Click(KeyCode.Return);
    eventBuilder.ClickChord(KeyCode.LControl, KeyCode.A);
    eventBuilder.Click(command);
    eventBuilder.Click(KeyCode.Return);

    if (setForegound)
    {
        // This is to fix the first SetForegroundWindow
        await Simulate.Events().Click(KeyCode.LMenu).Invoke();
        Native.SetForegroundWindow(this._windowHandle);
        await Task.Delay(10);
        var foregroundWindow = Native.GetForegroundWindow();
        if (this._windowHandle != foregroundWindow)
        {
            await Task.Delay(100);
        }
    }

    await eventBuilder.Invoke();
}

Is there anything I need to dispose?

TonyValenti commented 4 years ago

@C1rdec This looks good. When you're siumulating events, there is not thing you need to dispose of.

What does your app do and what is the nature of the key strokes that are randomly happening??

C1rdec commented 4 years ago

My app is a Path of Exile overlay (Poe Lurker) I've been using your older Library but I came across a Github Issue that was pointing here since you made a complete rewrite.

Basically as an example the user wanted to write "Thanks" and here is the resulting string.

image

A restart of my application fixed the issue.

One thing I can see is that I'm building 2 EventBuilders and I'm executing the second before the first one.

TonyValenti commented 4 years ago

Because EventBuilder is basically just a list, it doesn't actually do anything until you Invoke() it and I'm sure that what your'e doing is fine.

Have you been able to replicate the issue? Can you share a video of it happening?

Are you just using EventBuilder or are you using a keyboard listening functions as well?

C1rdec commented 4 years ago

Sorry for the delay... I'm just using the EventBuilder I will try to get you a video but basically I think there's multiple command that fire at the same times I think the issue might be on my side since I was not awaiting the call all the way up.

Here is the corresponding issue: https://github.com/C1rdec/Poe-Lurker/issues/211

I'll keep you updated if the issue still occurs.

C1rdec commented 4 years ago

The issue was on my side.