Auto type in chat

Ask gaming related questions (AHK v1.1 and older)
Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Auto type in chat

Post by Svestenik » 23 Mar 2021, 04:42

Could someone help me and make me a hotkey that is typing /forage in chat every 5 minutes, I have no clue how this thing works hahaha. Chat is opening on letter T. Thanks. :D

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 23 Mar 2021, 19:47

Code: Select all

Loop {
 Send {Text}/forage
 Sleep, 300000
}

Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Re: Auto type in chat

Post by Svestenik » 24 Mar 2021, 08:01

Thanks but its not working, nothing is happening when the script is running.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 24 Mar 2021, 09:29

This sends to the window that is active at the time. Does it work in Notepad?

Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Re: Auto type in chat

Post by Svestenik » 24 Mar 2021, 09:43

Yes it works in notepad, but I need it to press T so it opens chat in game, and then type in /forage and press enter. :)

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 24 Mar 2021, 10:02

You can add new Send commands wherever you need them, inside or before the loop.

Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Re: Auto type in chat

Post by Svestenik » 24 Mar 2021, 10:11

Thats why I asked someone to make it for me, because I have no clue how this thing works and how commands work

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 24 Mar 2021, 10:19

It's easy to learn. See the link that I sent for examples. Another is below. Send sends text to the active window.

Code: Select all

Send {Text}t
Sleep, 900
Loop {
 Send /forage{Enter}
 Sleep, 300000
}

Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Re: Auto type in chat

Post by Svestenik » 24 Mar 2021, 10:26

Now its working, thank you alot ill make sure to check it out, got some more hotkeys to make :D

Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Re: Auto type in chat

Post by Svestenik » 24 Mar 2021, 10:42

The script is acting weird, its opening other programs and its not putting in the correct command after 1st use, i dont know why is that, ill follow your guide and try to make another one.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 24 Mar 2021, 10:49

If a different window is active, then it will send to that window.
This script does what you can also replicate manually (or vice-versa). It is just sending the text to the active window, waiting, and repeating.
It assumes that your target window will remain active. To send to a different (inactive) window, see ControlSend.
The script itself does not open anything, but if you change the active window, it could unexpectedly trigger any number of actions in those other windows.

Svestenik
Posts: 7
Joined: 23 Mar 2021, 04:30

Re: Auto type in chat

Post by Svestenik » 24 Mar 2021, 12:39

I dont know I know how to type in text and enter it but i dont know a command that opens chat, i dont know how to make it press letter T.

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 24 Mar 2021, 20:27

Send t will send the letter t to the active window.

Explained: Send

MajesticRaven
Posts: 6
Joined: 31 Mar 2021, 19:34

Re: Auto type in chat

Post by MajesticRaven » 31 Mar 2021, 19:48

hey @mikeyww , sorry if it is not ok to @ you but you seem to be the man here.

I am trying to do basically what you are referring to in the above discussion I think but seem to be confusing my self. if possible I would like to start my script, have it select a specific program then type specific keystrokes in that program, press enter, then repeat once a minute. if possible to set a stop time for X Mins later that would be ever better.

here is the coding I was trying but was getting errors due to me not knowing what im doing

Code: Select all

^`::
if not Discord ("ahk_class Discord")
    return
; Otherwise,
ControlSend, ahk_parent, TEXT  ; 
Loop {ControlSend, ahk_parent, TEXT
 Sleep, 60112}
[Mod edit: [code][/code] tags added.]

I appreciate any time and effort you spending reading this and or replying, thank you so much in advance <3

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 31 Mar 2021, 21:39

Code: Select all

wTitle := "ahk_class Discord", control := "ahk_parent"
^`::
If !WinExist(wTitle) {
 MsgBox, 48, Error, Window was not found.`n`n%wTitle%
 Return
} Else SoundBeep, 1500, 120
ControlSend, %control%, TEXT
Sleep, 900
SetTimer, Go, 60000
SetTimer, Stop, -180000
Go:
ControlSend, %control%, /forage{Enter}, %wTitle%
Return
Stop:
SetTimer, Go, Off
Return

MajesticRaven
Posts: 6
Joined: 31 Mar 2021, 19:34

Re: Auto type in chat

Post by MajesticRaven » 31 Mar 2021, 23:19

thank you so much for that, I was way off!

when I run the script, windows is not finding the discord program. An error pops up saying "window not found. ahk_discord" I'm not too sure how to find the correct file name, I just put ahk_discord in my example because that's what the winamp tutorial said and I don't know better.
image.png
image.png (4.28 KiB) Viewed 5587 times
.
Attachments
image.png
image.png (4.28 KiB) Viewed 5587 times

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 01 Apr 2021, 06:28

Window Spy shows the complete window information including the window class. You could try the following, with this control value (ahk_parent), or setting it to null.

Code: Select all

wTitle := "ahk_class Chrome_WidgetWin_1 ahk_exe Discord.exe", control := "ahk_parent"
^`::
If !WinExist(wTitle) {
 MsgBox, 48, Error, Window was not found.`n`n%wTitle%
 Return
} Else SoundBeep, 1500, 120
ControlSend, %control%, TEXT
Sleep, 900
SetTimer, Go, 60112
SetTimer, Stop, -180000
Go:
ControlSend, %control%, /forage{Enter}, %wTitle%
Return
Stop:
SetTimer, Go, Off
Return
Explained: WinTitle

You can also look for a specific control, and use that control name in ControlSend. I found, for example, that a message control had a control name of Intermediate D3D Window1.

MajesticRaven
Posts: 6
Joined: 31 Mar 2021, 19:34

Re: Auto type in chat

Post by MajesticRaven » 01 Apr 2021, 11:59

I didn't think this would be an issue and I feel bad asking so much but...

the text I want to type is :-b but when I run the script it types out ;_b two times and nothing I'm doing is fixing either issue.

image.png
image.png (5.4 KiB) Viewed 5556 times

MajesticRaven
Posts: 6
Joined: 31 Mar 2021, 19:34

Re: Auto type in chat

Post by MajesticRaven » 01 Apr 2021, 12:01

Code: Select all

wTitle := "ahk_class Chrome_WidgetWin_1 ahk_exe Discord.exe", control := "ahk_parent"
^`::
If !WinExist(wTitle) {
 MsgBox, 48, Error, Window was not found.`n`n%wTitle%
 Return
} Else SoundBeep, 1500, 120
ControlSend, %control%, :-b
Sleep, 900
SetTimer, Go, 60112
SetTimer, Stop, -180000
Go:
ControlSend, %control%, ::-b{Enter}, %wTitle%
Return
Stop:
SetTimer, Go, Off
Return
^^ was the code I was using
Last edited by gregster on 01 Apr 2021, 12:53, edited 1 time in total.
Reason: [code] tags added. Please use them yourself. Thank you!

User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Auto type in chat

Post by mikeyww » 01 Apr 2021, 13:04

Interesting issue-- as Shift is somehow being inserted, presumably as AHK manages that key in sending :. Using {Text} might help you.

Code: Select all

ControlSend, %control%, {Text}::-b, %wTitle%
ControlSend, %control%, {Enter}   , %wTitle%

Post Reply

Return to “Gaming Help (v1)”