Sending keystrokes to a Minecraft window (active or not)

Ask gaming related questions (AHK v1.1 and older)
User avatar
Consolarificus
Posts: 19
Joined: 10 Feb 2016, 09:00

Sending keystrokes to a Minecraft window (active or not)

Post by Consolarificus » 24 Apr 2016, 22:00

I am trying to send the command /gamemode{space}c{enter} directly to a Minecraft window (using Ctrl + # key for this example), whether or not it is in focus.

Code: Select all

SendMode Input
SetTitleMatchMode, 2
^#::
        
       Sleep, 25 
       ControlSend, ahk_parent, t, Minecraft
        Sleep, 60
        ControlSend, ahk_parent, /, Minecraft
        Sleep, 30
        ControlSend, ahk_parent, g, Minecraft
                Sleep, 30
        ControlSend, ahk_parent, a, Minecraft
        Sleep, 30
        ControlSend, ahk_parent, m, Minecraft
        Sleep, 30
        ControlSend, ahk_parent, e, Minecraft
        Sleep, 30
        ControlSend, ahk_parent, m, Minecraft
        Sleep, 30
        ControlSend, ahk_parent, o, Minecraft
        Sleep, 30
        ControlSend, ahk_parent, d, Minecraft
                Sleep, 30
        ControlSend, ahk_parent, e, Minecraft
                Sleep, 30
        ControlSend, ahk_parent, {space}, Minecraft
                Sleep, 30
        ControlSend, ahk_parent, c, Minecraft
                Sleep, 30
        ControlSend, ahk_parent, {enter}, Minecraft
        Return
Minecraft will accept the first letter, t (brings up the chat window), and the last one, {enter}. I just can't figure out why it's not sending anything in between (this works in other windows such as a text editor).
I am using a similar script with GamePadZoo (with SendInput instead of ControlSend), and it's sending the keystrokes fine using these delays (I had too many issues with SetKeyDelay).

I've had no luck whether in full screen or windowed more...

Thanks

User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Sending keystrokes to a Minecraft window (active or not)

Post by evilC » 25 Apr 2016, 13:23

Try SetKeyDelay, 0, 50 at the start of the script.

The sleeps you have only affect the delay between the release of one key and the press of the next, whereas the above command affects the delay between the press of a key and the release of that key.
If a key is not held down for long enough, a game may not recognize it as being pressed.

User avatar
Consolarificus
Posts: 19
Joined: 10 Feb 2016, 09:00

Re: Sending keystrokes to a Minecraft window (active or not)

Post by Consolarificus » 25 Apr 2016, 18:27

Thanks! Works great now :)

ahnakin
Posts: 6
Joined: 10 Aug 2022, 18:08

Re: Sending keystrokes to a Minecraft window (active or not)

Post by ahnakin » 10 Aug 2022, 18:33

I can't get ControlSend to work at all in Minecraft Bedrock... I specify the class (as shown by the window spy), I have tried the title, blank, and ahk_parent. Nothing works.

I have read that some apps can't be controlled via ControlSend (which means AHK is worthless for AFK stuff in the background) yet I see multiple posts on here where people have ControlSend partially or completely working, and I wonder what I'm doing wrong!

thinkRand
Posts: 44
Joined: 02 Mar 2022, 04:16
Location: Somewhere in Venezuela
Contact:

Re: Sending keystrokes to a Minecraft window (active or not)

Post by thinkRand » 13 Aug 2022, 08:59

@ahnakin

Post your code to figure out the error.
Discord: thinkRand#7433 (UID 681695022600814642)

ahnakin
Posts: 6
Joined: 10 Aug 2022, 18:08

Re: Sending keystrokes to a Minecraft window (active or not)

Post by ahnakin » 12 Jan 2023, 21:46

thinkRand wrote:
13 Aug 2022, 08:59
@ahnakin

Post your code to figure out the error.
Sorry, I never saw this response. I guess I wasn't clear that I was trying the exact code in the first post of this thread. (I also tried code from other threads but it's been so long I have forgotten which ones.) I'm not sure what ahk_parent is though, so I also tried ApplicationFrameInputSinkWindow which is the ClassNN Window Spy tells me. There is no Text shown under it. I also tried with and without the "Minecraft" text as the last parameter, and with and without the SendMode and SetTitleMatchMode lines at the beginning. SendMode seems to be irrelevant anyway as it doesn't seem to affect ControlSend.

Post Reply

Return to “Gaming Help (v1)”