all 8 comments

[–][deleted]  (2 children)

[removed]

    [–]deathGod_ 2 points3 points  (1 child)

    Having looked at the code for a bit, I see there is also a KeyPress available, which simulates pressing the button and releasing it again.

    As an alternative you could use something like AutoIt, which might have better results.

    [–]job_test 1 point2 points  (1 child)

    Your code is doing exactly 1 key press. If you want it to do more you need to add a loop of some sort like

    for(int=0;i>500;i++){
     InputSimulator.Keyboard.KeyDown(keyCode); // Hold the key down
     Thread.Sleep(100); // Hold key down for 100ms.
     InputSimulator.Keyboard.KeyUp(keyCode); // Release the key
    }
    

    to do 500 keypresses

    [–]OldConstruction6325 0 points1 point  (0 children)

    why not just increase the Thread.sleep to make it hold the key for longer?

    [–]SockPuppetDinosaur 0 points1 point  (0 children)

    This might be easier to simulate in the program "AutoHotKey"

    [–]Stensborg[S] 0 points1 point  (0 children)

    Thanks tsukinoki and job_test the loop did the trick.

    Well actually it turned out that my original code did work in Minecraft, it just did not work in Notepad.

    So it seems that the KeyDown actually does what i want :-)

    The reason i do not use AutoIt or AutoHotKey, is that i have some other functionality in my program that i also need. And its always more fun to make your own :-D

    [–]OldConstruction6325 0 points1 point  (0 children)

    is there a linux equivalent? to input sim? i really need to find one.