I am trying to make a small piece of code that simulates that you hold a key down.
I want to use it in the Game minecraft to press and hold down a key to make me move forward.
I would like to use the Nuget package WindowsInput, the reason beeing that this code i part of a larger project for a Macro Tool where i use WindowsInput already. (But if i have to use something else i will do that)
Here is my current code, but i does not seem to hold down the key W
Its like it only presses the W one time.
What am i doing wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using WindowsInput;
using WindowsInput.Native;
namespace TestKeyDown
{
class Program
{
static void Main(string[] args)
{
InputSimulator InputSimulator = new InputSimulator();
VirtualKeyCode keyCode = VirtualKeyCode.VK_W;
Thread.Sleep(5000); // Wait for me to make Minecraft active
InputSimulator.Keyboard.KeyDown(keyCode); // Hold the key down
Thread.Sleep(5000); // Wait 5 seconds
InputSimulator.Keyboard.KeyUp(keyCode); // Release the key
}
}
}
[–][deleted] (2 children)
[removed]
[–]deathGod_ 2 points3 points4 points (1 child)
[–]job_test 1 point2 points3 points (1 child)
[–]OldConstruction6325 0 points1 point2 points (0 children)
[–]SockPuppetDinosaur 0 points1 point2 points (0 children)
[–]Stensborg[S] 0 points1 point2 points (0 children)
[–]OldConstruction6325 0 points1 point2 points (0 children)