jasonpang / Interceptor

C# wrapper for a Windows keyboard driver. Can simulate keystrokes and mouse clicks in protected areas like the Windows logon screen (and yes, even in games). Wrapping http://oblita.com/Interception
MIT License
286 stars 84 forks source link

Cant send Keys and input.SendKey does right click #21

Open fleeasura123 opened 3 years ago

fleeasura123 commented 3 years ago

Hi, this is my code. When I try SendKey it right clicks.

            Input input = new Input();
            input.KeyboardFilterMode = KeyboardFilterMode.All;
            input.MouseFilterMode = MouseFilterMode.All;
            input.Load();

            Thread.Sleep(2000);

            input.SendLeftClick();

            Thread.Sleep(2000);

            input.KeyPressDelay = 10;
            input.SendKey(Interceptor.Keys.C, KeyState.Down);
            Thread.Sleep(100);
            input.SendKey(Interceptor.Keys.C, KeyState.Up);

            input.SendKeys(Interceptor.Keys.A);

            input.Unload();
Jamisco commented 3 years ago

It's the Mouse Filter, It is bugged, like really bad.

Set the mouse filter to none and try again. I found out that if you set the mousefiltermode to all, the program starts an unstoppable thread... and fucks your mouse to the point where you need to restart your computer

kevinf100 commented 2 years ago

SendKey is not working due to it sending to the wrong device. SendKey sends it to whatever the last deviceId is. You send more mouse input than keyboard input so this is why it right click. My Pull #23 fixes this. I also fixed the unkillable thread. This is due to the use of Thread.Abort() being expected to always kill the thread. The truth is that it try's to kill the thread. This is even noted in https://docs.microsoft.com/en-us/dotnet/api/system.threading.thread.abort?view=net-5.0 "Calling this method usually terminates the thread."