0

I'm creating a sort of program that holds the letter W in games to avoid AFK penaltie

I tried reading the documentation but is a complete mess. Anyone knows how to do that?

  • 1
    It might be useful to understand why you're trying to do this. Are you looking to simulate someone typing to a person looking at the screen? Are you trying to automate some testing? The documentation you linked looks like touch input, like a pen on a tablet or something, that doesn't sound like what you're looking for. Perhaps post some code for what you've tried? – Kevon Nov 04 '22 at 16:14
  • @Kevon im doing a sort of program that holds the letter W in games to avoid AFK penalties –  Nov 04 '22 at 16:50
  • did you see this post: https://stackoverflow.com/questions/20482338/simulate-keyboard-input-in-c-sharp – Kevon Nov 04 '22 at 16:53
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 04 '22 at 21:19

1 Answers1

0

To inject keyboard input, you will need to create a InputInjector class first. It represents the virtual input device for sending the input data. Then you will need to create a InjectedInputKeyboardInfo Class which contains the key input. After that, you could call inputInjector.InjectKeyboardInput method to inject the keyboard input.

Please also note that the APIs in the Windows.UI.Input.Preview.Injection Namespace require the inputInjectionBrokered restricted capability.

Here is the code that you could refer to:

InputInjector inputInjector = InputInjector.TryCreate();

            var controlkey = new InjectedInputKeyboardInfo();
            controlkey.VirtualKey = (ushort)(VirtualKey.LeftControl);
            controlkey.KeyOptions = InjectedInputKeyOptions.None;

            var altkey = new InjectedInputKeyboardInfo();
            altkey.VirtualKey = (ushort)(VirtualKey.Menu);
            altkey.KeyOptions = InjectedInputKeyOptions.None;

            var delkey = new InjectedInputKeyboardInfo();
            delkey.VirtualKey = (ushort)(VirtualKey.Delete);
            delkey.KeyOptions = InjectedInputKeyOptions.None;

            inputInjector.InjectKeyboardInput(new[] { controlkey, altkey, delkey });

            controlkey.KeyOptions = InjectedInputKeyOptions.KeyUp;
            altkey.KeyOptions = InjectedInputKeyOptions.KeyUp;
            delkey.KeyOptions = InjectedInputKeyOptions.KeyUp;

            inputInjector.InjectKeyboardInput(new[] { controlkey, altkey, delkey });
Roy Li - MSFT
  • 8,043
  • 1
  • 7
  • 13